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 |
|
ritu2303
Starting Member
4 Posts |
Posted - 2009-04-16 : 06:37:27
|
| I have a table.TableID KeywordId RecordID keywordXrefID1 20 8 11 20 13 21 20 15 31 30 8 41 30 14 51 30 15 61 40 8 7If i pass the parameter keywordid(20,30,40) it should return me recordid 8 and if i pass the parameter keywordid(20,30) it should return the record id 8,15.Please help me in doing this. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-16 : 06:57:11
|
| select RecordID from your_tablegroup by RecordIDhaving sum(case when KeywordId in (20,30,40) then 1 else 0 end)=3MadhivananFailing to plan is Planning to fail |
 |
|
|
ritu2303
Starting Member
4 Posts |
Posted - 2009-04-16 : 07:03:41
|
| Hi madhivananThanks for replying for not working out.It is returning me no record id.One more thing why we are using sum clauseselect RecordID from your_tablegroup by RecordIDhaving sum(case when KeywordId in (20,30,40) then 1 else 0 end)=3 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-16 : 07:07:04
|
quote: Originally posted by ritu2303 Hi madhivananThanks for replying for not working out.It is returning me no record id.One more thing why we are using sum clauseselect RecordID from your_tablegroup by RecordIDhaving sum(case when KeywordId in (20,30,40) then 1 else 0 end)=3
Based on the sample datadeclare @t table(TableID int , KeywordId int, RecordID int, keywordXrefID int)insert into @tselect 1, 20, 8, 1 union allselect 1, 20, 13, 2 union allselect 1, 20, 15, 3 union allselect 1, 30, 8, 4 union allselect 1, 30, 14, 5 union allselect 1, 30, 15, 6 union allselect 1, 40, 8, 7select RecordID from @tgroup by RecordIDhaving sum(case when KeywordId in (20,30,40) then 1 else 0 end)=3MadhivananFailing to plan is Planning to fail |
 |
|
|
ritu2303
Starting Member
4 Posts |
Posted - 2009-04-16 : 07:15:29
|
| With ur data it is returning me the recordid 8 but if we remove the 40 from keyowrd(20,20,40) it is not returning anything |
 |
|
|
ritu2303
Starting Member
4 Posts |
Posted - 2009-04-16 : 07:38:26
|
| Its solved. So please dont try. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2009-04-16 : 07:45:14
|
| Care to share your solution?[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQL or How to sell Used CarsFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|
|
|