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 |
|
geoffsmiths
Starting Member
7 Posts |
Posted - 2010-05-31 : 09:29:39
|
| Hi all!I have 2 tables. I want the following managed in an SQL query:If table_1 has 0 records, show results from table_2.Can somebody share his/her expertise please?My regards,Geoff |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-31 : 10:04:34
|
if (select count(*) from table_1)>0beginselect * from table_1endelsebegin select * from table_2end No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
geoffsmiths
Starting Member
7 Posts |
Posted - 2010-05-31 : 10:11:48
|
| Webfred, you rule! How did you get that much knowledge?Anyways, thanx again! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-31 : 10:25:01
|
I have learned so much since I have joined this forums The other mates here (like Tara, Peso, Kristen, Visakh, Madhi, Khtan, Gail, TG, sodeep, Charly and many others) are awesome!This can be faster for big tables...but I have not tested.Give it a try pleaseif exists(select * from table_1)beginselect * from table_1endelsebegin select * from table_2end No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
geoffsmiths
Starting Member
7 Posts |
Posted - 2010-05-31 : 10:29:18
|
| Thanx for the tips.Your SQL worked great! It also works fine with small tables.My regards! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-31 : 10:30:26
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|