sql server - SQL Set/Declare Variable -


i set

declare @area varchar(500)  set @area = '''area1'',''area2''' 

i tried put in where clause, doesn't detect area. guessing there wrong set @area =?

this i'm trying bring in:

where area in (@area) 

please help, thanks.

since you've got list of elements compare against, use table variable accumulate comparison data, e.g.:

declare @area table(name varchar(50)); insert @area(name) values ('area1'), ('area2'); 

you can use either:

select *  mytable mycol in (select name @area); 

or better, via direct join (failed joins eliminated):

select *  mytable inner join @area on mytable.mycol = @area.name; 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -