From: Peter Newman on
Declare @TTranType varchar(2)

Case myTable.dbo.Col1
When 'A' then '01'
When 'B' Then '02'
Else '99'
End

My question is is there a simple way to assign @TTranType to the result of
the case. ie if col1 = A than @TTranType will = '01'
From: Tom Moreau on
Assuming there is only one row in the table:

select
@TTranType = case Col1
when 'A' then '01'
when 'B' then '02'
else '99'
end
from
dbo.MyTable

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


"Peter Newman" <PeterNewman(a)discussions.microsoft.com> wrote in message
news:F3AE7B11-7B13-48D5-8854-136D0EE80CBD(a)microsoft.com...
Declare @TTranType varchar(2)

Case myTable.dbo.Col1
When 'A' then '01'
When 'B' Then '02'
Else '99'
End

My question is is there a simple way to assign @TTranType to the result of
the case. ie if col1 = A than @TTranType will = '01'

From: Plamen Ratchev on
You your query guarantees a single row will be returned, then you can assign it like this:

DECLARE @TTranType VARCHAR(2);

SET @TTranType = (SELECT CASE col1
WHEN 'A' THEN '01'
WHEN 'B' THEN '02'
ELSE '99'
END
FROM myTable
WHERE keycol = 1);

--
Plamen Ratchev
http://www.SQLStudio.com