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
 SQL Server Development (2000)
 Using SUBSTRING inside a CASE statement

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-17 : 10:39:23
Michael writes "I have created a smaller version of what I am trying to do, but have been scratching my head for 2 days now on this, it seems logical, but I just can't seem to get it to work .. I hope it makes sence and hope you can help .. Thanks and Kindest Regards Mike


create table tblTable (row char(1),seat char(1))
go
declare @booking char(3)
set @booking = 'ia6'

CASE WHEN SUBSTRING(@booking, 1, 1) = 'i' then insert into tblTable (row,seat) values (SUBSTRING(@booking,2,1), SUBSTRING(@booking,3,1))
ELSE WHEN SUBSTRING(@booking, 1, 1) = 'd' then delete from tblTable where row = SUBSTRING(@booking,2,1) and seat = SUBSTRING(@booking,3,1)
end"

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-17 : 10:46:53
use IF ... ELSE instead



KH


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-17 : 10:47:46
Something like

If SUBSTRING(@booking, 1, 1) = 'i'
insert into tblTable (row,seat) values (SUBSTRING(@booking,2,1), SUBSTRING(@booking,3,1))
else If SUBSTRING(@booking, 1, 1) = 'd'
delete from tblTable where row = SUBSTRING(@booking,2,1) and seat = SUBSTRING(@booking,3,1)


Madhivanan

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

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-04-18 : 01:53:27
or you can create 2 separate sprocs for this since they are different in logic anyways,

they'll be easier to debug and maintain

HTH

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -