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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Multiple Conditionals....

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)
Begin
Print 'adding new record'
end
else
begin
print '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'
End

end



Thanks 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
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-08-20 : 13:25:04
If ((select count(ID) from somewhere where something)=0)
better as
If 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.
Go to Top of Page

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
)
Begin

Print 'Add A New Record - No One FROM USA'

End

Else
Begin
--We now do a sub query conditional once we know we have people from USA


If (
(Select Count(employeeID) from employees where City='Seattle') = 0
)
Begin
print 'We Dont have anyone from seattle'
End
Else
print 'we have people from seattle'
End

End

And the error I keep getting is incorrect syntax near END.....
Go to Top of Page

interclubs
Yak Posting Veteran

63 Posts

Posted - 2004-08-20 : 13:33:15
Scratch that, figured it out. Missing 'Begin'

Dohhhh!
Go to Top of Page
   

- Advertisement -