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
 Triggers

Author  Topic 

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-17 : 02:13:25
BEGIN
CASE
WHEN (SELECT count(*) from inserted Where seatloc = '') = 1 Then
BEGIN
print 'waiting list passenger'
END
WHEN (SELECT count(*) from inserted WHERE seatloc = 0) = 1 Then
RAISERROR 10002 'seat 0 does not exist'
ROLLBACK TRANSACTION
RETURN
ELSE
print 'Ticket confirmed'

END
When i execute above code, i get following error. What is wrong?
Error:

Msg 156, Level 15, State 1, Procedure status, Line 9
Incorrect syntax near the keyword 'CASE'.
Msg 102, Level 15, State 1, Procedure status, Line 11
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure status, Line 15
Incorrect syntax near the keyword 'WHEN'.
Msg 102, Level 15, State 1, Procedure status, Line 15
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure status, Line 19
Incorrect syntax near the keyword 'ELSE'.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-17 : 02:47:29
Try

BEGIN

IF (SELECT count(*) from inserted Where seatloc = '') = 1 Then
BEGIN
print 'waiting list passenger'
END
IF (SELECT count(*) from inserted WHERE seatloc = 0) = 1 Then
RAISERROR 10002 'seat 0 does not exist'
ROLLBACK TRANSACTION
RETURN
ELSE
print 'Ticket confirmed'
END


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-17 : 03:00:37
I knew that.. But why is CASE not working??
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-17 : 03:56:19
Hi
SELECT
CASE
WHEN
(SELECT COUNT(*)
FROM inserted
WHERE seatloc = ''
)
= 1
THEN 'waiting list passenger'
END,
CASE
WHEN
(SELECT COUNT(*)
FROM inserted
WHERE seatloc = 0
)
= 1
THEN 'seat 0 does not exist'
ELSE 'Ticket confirmed'
END


what madhi is said is right.. no need to use CASE statement..
Also refer...
http://msdn.microsoft.com/en-us/library/ms181765.aspx

-------------------------
R..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-17 : 06:28:11
quote:
Originally posted by sharankruthi

I knew that.. But why is CASE not working??


Read about CASE expression in SQL Server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -