Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2009-06-08 : 03:03:37
|
| based on userid i need to select the table name for fbidselect * from Rev_fbp_posted_dim_tb_tmp2(nolock)where fbid like case when @USERID <> ('admin','1206') then select fbid from table1 else select fbid from table2end |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-08 : 03:10:15
|
select * from Rev_fbp_posted_dim_tb_tmp2(nolock)where fbid in case when @USERID not in ('admin','1206') then select fbid from table1else select fbid from table2end No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-08 : 03:15:31
|
| try these solutionssolution 1: IF @userID <> ('admin','1206')select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table1 b on b.fbid = a.fbidelseselect * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table2 b on b.fbid = a.fbidSolution 2:select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table1 b on b.fbid = a.fbidwhere @userID <> ('admin','1206')union select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table2 b on b.fbid = a.fbid |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-08 : 03:24:32
|
quote: Originally posted by webfred select * from Rev_fbp_posted_dim_tb_tmp2(nolock)where fbid in case when @USERID not in ('admin','1206') then select fbid from table1else select fbid from table2end No, you're never too old to Yak'n'Roll if you're too young to die.
I think your query will not work when subquery returned more than one value.. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-08 : 03:42:01
|
quote: Originally posted by raky
quote: Originally posted by webfred select * from Rev_fbp_posted_dim_tb_tmp2(nolock)where fbid in case when @USERID not in ('admin','1206') then select fbid from table1else select fbid from table2end No, you're never too old to Yak'n'Roll if you're too young to die.
I think your query will not work when subquery returned more than one value..
And I think your query will bring up an error while mine is running because I am using IN. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-08 : 03:51:54
|
quote: Originally posted by raky try these solutionssolution 1: IF @userID <> NOT IN ('admin','1206')select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table1 b on b.fbid = a.fbidelseselect * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table2 b on b.fbid = a.fbidSolution 2:select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table1 b on b.fbid = a.fbidwhere @userID <> NOT IN ('admin','1206')union select * from Rev_fbp_posted_dim_tb_tmp2 as ainner join table2 b on b.fbid = a.fbid
beside the <> / NOT IN syntax error, the 2 solution will gives different result.For Solution 1, either one of the query will execute.In Solution 2, the 2nd query (after the union) will always execute KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|