Must declare the scalar variable "@collectionId"
使用しても、以下のクエリがあり、エラーが発生します[GetAllProductById] 6,0,0,0,'A122'
ALTER proc [dbo].[GetAllProductById]
(
@collectionId int,
@GrandId int ,
@ParentId int ,
@ChildId int,
@dealerid varchar(50)
)
As
Begin
Declare @sql as varchar(max)
-- In case dealer is logged in ,then calculate the Discounted amount and return the same,
-- else return Mrp and Our Price for all other customers
IF @collectionid<=0
BEGIN
IF @dealerid<>''
BEGIN
SET @sql = ' Select Top(5) Product.Id,ProdImage,ProductCode, ProductName,MrpPrice, BasicPrice,ValueAdd, Price =ISNULL((Product.BasicPrice + ValueAdd),0),
Discounted = ISNULL((Select (Product.BasicPrice + (ValueAdd -(ValueAdd *(Discount*0.01))))
From DealerDiscount
Where CategoryId = Product.GrandCategoryId AND DealerId='+@dealerid+'),0)
From Product Where 1=1 ';
END
ELSE
BEGIN
SET @sql = ' Select Top(5) Id,ProdImage,ProductCode, ProductName,MrpPrice, BasicPrice,ValueAdd, Price =ISNULL((BasicPrice + ValueAdd),0), Discounted=0
From Product
Where 1=1 ';
END
END
ELSE
BEGIN
IF @dealerid<>''
BEGIN
SET @sql = ' Select Product.Id,ProdImage,ProductCode,Collections.Name,Collections.Id, ProductName,MrpPrice, BasicPrice,ValueAdd, Price =ISNULL((Product.BasicPrice + ValueAdd),0),
Discounted = ISNULL((Select (Product.BasicPrice + (ValueAdd -(ValueAdd *(Discount*0.01))))
From DealerDiscount
Where CategoryId = Product.GrandCategoryId AND DealerId='+@dealerid+'),0)
FROM Collections INNER JOIN
Product ON Collections.Id = Product.CollectionId
where Product.CollectionId=@collectionId AND 1=1 ';
END
ELSE
BEGIN
SET @sql = ' Select Product.Id,ProdImage,Collections.Name,Collections.Id,ProductCode, ProductName,MrpPrice, BasicPrice,ValueAdd, Price =ISNULL((BasicPrice + ValueAdd),0), Discounted=0
FROM Collections INNER JOIN
Product ON Collections.Id = Product.CollectionId
where Product.CollectionId=@collectionId AND 1=1 ';
END
if (@GrandId > 0 and @ParentId>0 and @ChildId > 0 and @collectionId=0)
Begin
Set @sql = @sql + ' Product.ParentCategoryId = '+ Convert(Varchar, @ParentId)+' AND Product.GrandCategoryId = '+ Convert(Varchar, @GrandId)+' AND Product.ChitdCategoryId = '+Convert(varchar,@ChildId);
End
if (@GrandId > 0 and @ParentId>0 and @ChildId = 0 and @collectionId=0)
Begin
Set @sql = @sql + ' Product.ParentCategoryId = '+ Convert(Varchar, @ParentId)+' AND Product.GrandCategoryId = '+ Convert(Varchar, @GrandId)
End
if (@GrandId > 0 and @ParentId=0 and @ChildId = 0 and @collectionId=0)
Begin
Set @sql = @sql + ' AND Product.GrandCategoryId = '+ Convert(Varchar, @GrandId)
End
END
exec(@sql)
END