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 |
|
zion99
Posting Yak Master
141 Posts |
Posted - 2009-01-21 : 01:08:08
|
| Hi All,following is the query:declare @groupfindid intset @groupfindid = 3declare @tbl1 TABLE(rowid int,rowname varchar(10),groupid int)insert into @tbl1select 100,'view 1',10 union allselect 200,'view 2',20 union allselect 300,'view 2',20 union allselect 400,'view 1',10 union allselect 500,'view 2',20 union allselect 600,'view 2',20 union allselect 700,'view 1',10select * from @tbl1 where groupid = CASE WHEN @groupfindid = 1 then 10 WHEN @groupfindid = 2 then 20 --WHEN @groupfindid = 3 then ???? --ISSUE HERE END@groupfindid = 1 displays records with groupid = 10@groupfindid = 2 displays records with groupid = 20@groupfindid = 3 displays ALL recordsi m not understanding what condition should i be putting in '@groupfindid = 3' so that all records are retrievedthnx :) |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-01-21 : 01:11:43
|
| declare @groupfindid intset @groupfindid = 3declare @tbl1 TABLE(rowid int,rowname varchar(10),groupid int)insert into @tbl1select 100,'view 1',10 union allselect 200,'view 2',20 union allselect 300,'view 2',20 union allselect 400,'view 1',10 union allselect 500,'view 2',20 union allselect 600,'view 2',20 union allselect 700,'view 1',10select * from @tbl1 where groupid = CASE WHEN @groupfindid = 1 then 10 WHEN @groupfindid = 2 then 20WHEN @groupfindid = 3 then groupid--Use this ENDRahul Shinde |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-21 : 01:16:23
|
| declare @groupfindid intset @groupfindid = 1select * from @tbl1where groupid = CASE WHEN @groupfindid= 1 then 10 WHEN @groupfindid = 2 then 20 else groupidEND |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-01-21 : 01:21:35
|
quote: Originally posted by bklr declare @groupfindid intset @groupfindid = 1select * from @tbl1where groupid = CASE WHEN @groupfindid= 1 then 10 WHEN @groupfindid = 2 then 20 else groupidEND
With this solution, if @groupfindid is other than 1 and 2, then it will return all records. What we require is when @groupfindid = 3 then ALL records should be returnedRahul Shinde |
 |
|
|
zion99
Posting Yak Master
141 Posts |
Posted - 2009-01-21 : 01:28:48
|
aarghh...how very foolish of me...thanks to both of you |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-21 : 01:30:59
|
quote: Originally posted by zion99 aarghh...how very foolish of me...thanks to both of you 
ur welcome |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-01-21 : 01:36:16
|
quote: Originally posted by zion99 aarghh...how very foolish of me...thanks to both of you 
WelcomeRahul Shinde |
 |
|
|
|
|
|
|
|