Last post Feb 19, 2015 07:47 AM by PatriceSc
Feb 19, 2015 02:16 AM|fungus.00|LINK
Im having some problem in my query I want to check range within IN clasue
but it gives me an error "Incorrect syntax near '@LevelCode"
DECLARE @POCostCentreCode varchar(50)
DECLARE @Range nvarchar(100)
SET @Range = '90,99'
SET @LevelCode = 90
SELECT @POCostCentreCode = POCostCentreCode
AND CostCentreID IN (SELECT iCostCenterID
IF @POCostCentreCode IN (@Range)
@LevelCode + 1
Thanks in advance
Feb 19, 2015 07:47 AM|PatriceSc|LINK
IN is part of SQL and can't be used outside of a SQL statement. Anyway you can't use variables this way. It doesn't work by just replacing the text with the variable content and then running the line. You can use variables only where a literal value of the
same type can be used (for example not to define a table name in a FROM clause).
You'll likely have to explain rather what you want to so that someone can help. For example iCostCenterID comes from a table whose name is not always the same?