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 |
|
interclubs
Yak Posting Veteran
63 Posts |
Posted - 2004-08-20 : 13:15:05
|
| I can't figure out how to do multiple conditionals in a select statement... Been trying to do something like below, but been striking out every which way on it.If ((select count(ID) from somewhere where something)=0)BeginPrint 'adding new record'endelsebeginprint 'They are in here already'-- Now we need to Do another conditional in HERE.--Which I can't get to work If ((select count(ID) from somewhere where something more specific happens)=0) Begin Print 'Updating Record one way' end else begin print 'updating record another way' EndendThanks Guys. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-08-20 : 13:17:59
|
| Could you provide a better example? And also explain what is going wrong?Tara |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-08-20 : 13:25:04
|
| If ((select count(ID) from somewhere where something)=0)better asIf not exists (select * from somewhere where something=0)begin...The syntax you have looks ok==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
interclubs
Yak Posting Veteran
63 Posts |
Posted - 2004-08-20 : 13:31:15
|
| Here is a Northwinds Example....If ((Select Count(employeeID) from employees where country='USA') = 0)BeginPrint 'Add A New Record - No One FROM USA'EndElseBegin--We now do a sub query conditional once we know we have people from USAIf ((Select Count(employeeID) from employees where City='Seattle') = 0)Beginprint 'We Dont have anyone from seattle'EndElseprint 'we have people from seattle'EndEndAnd the error I keep getting is incorrect syntax near END..... |
 |
|
|
interclubs
Yak Posting Veteran
63 Posts |
Posted - 2004-08-20 : 13:33:15
|
| Scratch that, figured it out. Missing 'Begin'Dohhhh! |
 |
|
|
|
|
|