| Author |
Topic |
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-10-03 : 10:59:33
|
| In my query say, Select col001,col002,col003 from Table1 where col003=somevalue this will return records which matches the criteria.In case if the criteria does not produce any records then I need to have a default value, something like 0 to be returned for each column. Any way its possible?Karunakaran |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-10-03 : 11:07:43
|
Union a 'defaulted' record with the result set. then take max...or write the results to a temp table, and then check the count ... if 0 then select defaults... else select resulstsCorey Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..." |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2005-10-03 : 12:30:30
|
| ... or do it on the client. |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-10-03 : 14:33:37
|
quote: Originally posted by mmarovic ... or do it on the client.
true... that should be the first choice ... but I assumed that since they were asking, that is not an option... Corey Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..." |
 |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-10-03 : 23:56:06
|
| Thanks for the ideas...Karunakaran |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-10-04 : 00:48:00
|
| if this is in sproc, you can set the variable to a default value@field varchar(10)='any value'it really depends on what you want to select...--------------------keeping it simple... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-04 : 00:57:08
|
How about this?If Exists(Select * from Table1 where col003=somevalue) Select col001,col002,col003 from Table1 where col003=somevalue else Select 0 as col1 ,0 as col2,0 as col3 MadhivananFailing to plan is Planning to fail |
 |
|
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-10-04 : 09:29:59
|
| Its in Stored Proc, if exists solution looks easier....Karunakaran |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-04 : 10:15:41
|
| So which one do you want to follow?MadhivananFailing to plan is Planning to fail |
 |
|
|
|