|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
local variables in case statment
Hi
I am trying to use a global variable in a case when and am not getting the correct results. If I use static data, it works fine. Here is a tableless example, which should return Shipper. Any ideas are appreciated. Code:
declare @shipperGBS varchar(3000)
declare @sQuote char
set @sQuote = char(39)
set @shipperGBS = 'ACI,ADO,ALD,AMS,AWB'
set @shipperGBS = Replace(@shipperGBS, ',', @sQuote + ',' + @sQuote)
set @shipperGBS = @sQuote + @shipperGBS + @sQuote
select case when ('ACI' IN (@shipperGBS)) then 'Shipper' else 'Consignee' end as ClientCharge
|
|
#2
|
|||
|
|||
|
As @shipperGBS holds the value 'ACI','ADO','ALD','AMS','AWB'
'ACI' IN (@shipperGBS) can never be true. You can solve this by using dynamic sql Code:
exec('select case when ''ACI'' in (' + @shipperGBS + ') then ...')
but that should be avoided. Describe the real problem instead. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > local variables in case statment |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|