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
 wrong syntax??

Author  Topic 

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2010-05-10 : 01:10:25
Hi,

declare @i int

set @i = 4

if (SELECT count(1) FROM a WHERE id = 3) = 3 then
exit

insert into a
values (@i)

error:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'then'.


please suggest

T.I.A

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-05-10 : 01:15:32
If doesn't have "then"

http://msdn.microsoft.com/en-us/library/aa933214(SQL.80).aspx

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-10 : 01:16:12
the IF..ELSE syntax does not have a THEN. THEN is used with CASE .. WHEN

refer to http://msdn.microsoft.com/en-us/library/ms182717.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-10 : 01:16:34



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2010-05-10 : 01:18:15
hi,

i have multiple insert into temp table statement below this loop

so i dont want to execute these so i want to exit the whole SP if it gets above condition value.

T.I.A
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-10 : 01:21:01
[code]
if (SELECT count(1) FROM a WHERE id = 3) <> 3
BEGIN
< the multiple insert into temp table statement >
END
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -