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 |
|
besadmin
Posting Yak Master
116 Posts |
Posted - 2010-05-27 : 15:50:16
|
| Hey. I bet this is an easy solution, but I am stuck.I am trying to do if Exists(Select * from Whatever)ELSE Insert whatever.The only part I am having touble with is how do i return the row, if the IF EXISTS is true. Will it just return, or do i need to do something like 'return' or if exsists (select) then Select.Thanks a ton for any help with this!Later |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-27 : 16:06:07
|
if Exists(Select * from Whatever)beginSelect * from Whateverendelsebegin insert whateverend No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2010-05-27 : 16:06:38
|
select *into #tmpfrom mytableif @@RowCount > 0begin select * from #TMPendelsebegin insert into ...end Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
besadmin
Posting Yak Master
116 Posts |
Posted - 2010-05-27 : 16:47:14
|
| OK, got it. Pretty much what I was thinking. just seems like there should be a better way to do if select = something then select... but it works.Thanks a ton for the replys!! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-05-27 : 16:51:31
|
Yes in exists() no rows are returned - only a boolean.So if true you have to do the select again to return rows. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|