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 |
|
asif372
Posting Yak Master
100 Posts |
Posted - 2011-11-24 : 04:33:12
|
| Dear,I want to include condition in Where ClauseMy Query is this but Case is not WorkingDECLARE @Emp NVARCHAR(50)SET @Emp = 40Select * from EmployeeWHERE(Case When @EMP = 40 then Group = 1When @EMP = 42 then Group = 2)Kindly HelpThanks |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-11-24 : 04:35:46
|
| DECLARE @Emp NVARCHAR(50)SET @Emp = 40Select * from EmployeeWHERE Group = Case When @EMP = 40 then Group = 1 When @EMP = 42 then Group = 2 END |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-11-24 : 04:38:33
|
[code]Select * from EmployeeWHERE Group = (Case When @EMP = 40 then Group = 1 When @EMP = 42 then Group = 2 end)[/code]OR[code]Select *from Employeewhere (@EMP = 40 AND Group = 1)OR (@EMP = 42 AND Group = 2)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
asif372
Posting Yak Master
100 Posts |
Posted - 2011-11-24 : 04:47:33
|
| Dear,i dont want to search for 1 field i want conditions to search from different fields. when user select 40 it should search from groupand when user select 42 it should search from group2Like this(Case When @EMP = 40 then Group = 1When @EMP = 42 then Group2 = 1)Kindly Help |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-24 : 05:02:26
|
Did you try the given solutions or do you think you are able to see - without trying - that they would not work? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
asif372
Posting Yak Master
100 Posts |
Posted - 2011-11-24 : 07:43:26
|
| Dear,I want to include condition in Where Clausewhen @EMP = 40 then it should Group1 = 1ElseGroup2 = 1My Query is this but Case is not WorkingDECLARE @Emp NVARCHAR(50)SET @Emp = 40Select * from EmployeeWHERE(Case When @EMP = 40 then Group1 = 1When @EMP = 42 then Group2 = 1)Kindly HelpThanks |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-11-24 : 07:49:17
|
| DECLARE @Emp NVARCHAR(50)SET @Emp = 40Select * from EmployeeWHERE Case When @EMP = 40 then Group1 When @EMP = 42 then Group2 END = Case When @EMP = 40 then 1 When @EMP = 42 then 2 END |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-11-24 : 07:49:33
|
Try this please:Select * from EmployeeWHEREGroup1 = CASE WHEN @EMP = 40 THEN 1 ELSE Group1 ENDANDGroup2 = CASE WHEN @EMP = 42 THEN 1 ELSE Group2 END No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|