Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

IN with variable

I have the following query

Select * From Table
Where AssetType  IN(1,2,3)

How would i change it so that there would be a variable for the items being passed in something like this?



DEClare @AssetList as varchar

Select * From Table
Where AssetType  IN( @AssetList)

This will be used in a SSRS report
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

The only way to pull that off is with dynamic SQL

Declare @AssetList varchar(1000) = '1, 2, 3'

Declare @sql nvarchar(1000) 
SELECT @sql = 'Select * From Table Where AssetType  IN (' +  @AssetList + ') '

exec sp_executesql @sql

Open in new window

Avatar of vbnetcoder
vbnetcoder

ASKER

Do you know if this will work in a SSRS report?
Don't know about T-SQL within an SSRS, but it will work in a Stored Procedure.  
Tell me how 1, 2, 3 is determined, as there are other ways to pull off multiple-value parameters in SSRS.
they will probable enter them as a comma separated list in SSRS

1, 2, 3
any query that you would suggest with SSRS?
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ty