Thursday, March 29, 2012

Error is SQL block

I want to know the error in the following SQL block,

I want to know, what is the error in the below block,

BEGIN

Declare @.StoreIdasvarchar(20)

Declare @.DepartmentIdasvarchar(20)

Declare @.VendorNumberasvarchar(20)

Declare @.SortByasint

Declare @.AllVendorSelectedasint

Declare @.SQLasnvarchar(500)

Set @.StoreId='1'

Set @.DepartmentId='NONE'

Set @.VendorNumber='NONE'

Set @.SortBy= 0

Set @.AllVendorSelected= 0

SET @.SQL='SELECT

Inventory.ItemNum

,Inventory.ItemName

,Inventory.ItemName_Extra

,Inventory.Dept_ID

,Inventory.In_Stock

,Inventory.Cost

,Inventory.Price

,Inventory.NumBoxes

,Inventory.NumPerCase

,Inventory.Store_ID

,Departments.Description

FROM

Inventory

INNER JOIN Departments ON Inventory.Store_ID = Departments.Store_ID AND Inventory.Dept_ID = Departments.Dept_ID

LEFT OUTER JOIN Inventory_Vendors ON Inventory.ItemNum = Inventory_Vendors.ItemNum AND Inventory.Store_ID = Inventory_Vendors.Store_ID

WHERE

Inventory.Store_Id in (@.StoreId)

AND Inventory.Dept_ID in (@.DepartmentId)

AND (@.AllVendorSelected = 1 OR Inventory_Vendors.Vendor_Number in (@.VendorNumber))'

IF(@.SortBy= 0)

SET @.SQL= @.SQL+'ORDER BY Inventory.ItemNum'

ELSE

SET @.SQL= @.SQL+'ORDER BY Inventory.ItemName'

EXEC @.SQL

END

I see several errors, mostly to do with this.

WHERE

Inventory.Store_Id in (@.StoreId)

AND Inventory.Dept_ID in (@.DepartmentId)

AND (@.AllVendorSelected = 1 OR Inventory_Vendors.Vendor_Number in (@.VendorNumber))'

|||

I hate this editor.

Anyway, you can't stick @.StoreId in there like that if it may ever have multiples (I see a single here, but assume it's a test or you would not use IN). You need to use '+@.StoreId+' instead. Same goes for the other fields like that.

sql

No comments:

Post a Comment