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
 General SQL Server Forums
 New to SQL Server Programming
 if statement in sql

Author  Topic 

MyronCope
Starting Member

46 Posts

Posted - 2008-01-15 : 12:25:27
question: i want to create an if statement in the sql that says something like this (pseudo code):

If not (select * from table where id=1) exists then
update record

how do i do this in sql?

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-01-15 : 12:29:51
IF NOT EXISTS (SELECT * FROM table WHERE id = 1)
BEGIN
.. Do something ..
END
ELSE (IF...)
BEGIN
.. Do something ..
END

"...database development, while a serious pursuit and vitally important to business, should be fun!"
-Adam Machanic
Go to Top of Page
   

- Advertisement -