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 |
|
John Sourcer
Yak Posting Veteran
91 Posts |
Posted - 2005-08-22 : 10:07:47
|
| Hi Guru'sIs the only possible way to do this in a stored procedure using dynamic sql?SELECT name, (SELECT COUNT(id) FROM families WHERE IF len(name) = 8 name = 'This name' ESLE name = 'That name' ) FROM names I know this isn't the best demo code. Basically I am trying to change the where clause in the count statement depending on the length of the 'name' in the first column! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-22 : 10:30:01
|
| Some like thisSELECT name, (SELECT COUNT(id) FROM families WHERE name = case when len(name) = 8 then 'this name' ELSE 'that name' end) as NameCountFROM namesMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
John Sourcer
Yak Posting Veteran
91 Posts |
Posted - 2005-08-22 : 10:35:39
|
| Thanks madhivanan,How about the following?SELECT name, (SELECT COUNT(id) FROM families WHEREIF len(name) = 8 this = thatESLE that = this ) FROM namesI think the only way is a dynamic query. Would you agree? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-22 : 10:40:38
|
| It is difficult to give solution until you give more informationPost the table structures, sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
John Sourcer
Yak Posting Veteran
91 Posts |
Posted - 2005-08-23 : 02:22:20
|
| Sorry!I have solved the problem! Thanks I will follow these guidelines in future! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-23 : 02:36:02
|
quote: Originally posted by John Sourcer Sorry!I have solved the problem! Thanks I will follow these guidelines in future!
Can you show us the query you used?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|