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)
 help with CASE statment

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-04-04 : 11:40:10
why this case illigeal or impossible?

SELECT @PI =
Case
WHEN @PI='N' THEN @PI=0
WHEN @PI=N'SENDER' then SELECT PR from tblData WHERE mobile=@S
WHEN @PI=N'RECIPIENT' then SELECT PR from tblData WHERE mobile=@R
End

thnaks i nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-04 : 11:44:45
[code]
SELECT @PI =
Case
WHEN @PI='N' THEN @PI= 0
WHEN @PI=N'SENDER' then (SELECT PR from tblData WHERE mobile=@S)
WHEN @PI=N'RECIPIENT' then (SELECT PR from tblData WHERE mobile=@R)
End
[/code]


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-04 : 11:49:21
OR


SELECT @PI = case when @PI = 'N'
then 0
else PR
end
FROM tblData
where @PI = 'N'
or mobile = case when @PI = 'SENDER' then @S
when @PI = 'RECIPIENT' then @R
end



KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-04 : 12:45:39
Or
IF @PI = 'Sender'
SELECT @PI = PR
FROM tblData
WHERE Mobile = @S
ELSE
IF @PI = 'Recipient'
SELECT @PI = PR
FROM tblData
WHERE Mobile = @R
ELSE
IF @PI = 'N'
SET @PI = '0'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-04-05 : 03:51:24
thnaks all of u!
by the way : is one of the way's it better in performance then the others?

Thnaks
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-05 : 04:04:12
Set the execution plan and see

Madhivanan

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

- Advertisement -