[T-SQL] Trouble with the IN keyword |
Posted: 04 May 2013 04:17 AM PDT I am creating a script where I am querying a table using the IN keyword.When I type the data inside the IN clause, the query performs as i should. But when I create a variable with the exact same data in it and use the variable inside the IN clause, it does not. Any Ideas???Here is the query that worksSELECT * FROM scpcommandeventlog WHERE MESSAGEid = 3 AND PARAM1 IN('11416407','11416410','11416413','11416417','11416419','11416421','11416423','11416427','11416432','11416433','11416434','11416435','11416438','11416443','11416446','11416448','11416451','11416454','11416458','11416462')here is the query that doesn'tSELECT * FROM scpcommandeventlog WHERE MESSAGEid = 3 AND PARAM1 IN(@list)Here is the query that populates the @list variableDECLARE @List varchar(max)SELECT @List = isnull(@List + ',', '') + '''' + cast(itemid as varchar) + ''''FROM dbo.ItemListWHERE sortid LIKE @sortid |
You are subscribed to email updates from SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8) To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment