Re: CASE statement
From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 11/18/04
- Next message: Ramnadh: "RE: Performance Issue"
- Previous message: smk23: "CASE statement"
- In reply to: smk23: "CASE statement"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Nov 2004 22:17:42 -0600
The CASE syntax looks fine except that you should enclose the literal in
single quotes instead of double quotes so that it will work regardless of
the QUOTED_IDENTIFIER setting. For example:
SELECT
CASE col1
WHEN 1 THEN 'okay'
WHEN 2 THEN p.LastName
END As result
FROM MyTable p
-- Hope this helps. Dan Guzman SQL Server MVP "smk23" <smk23@discussions.microsoft.com> wrote in message news:A7EFCFCB-FB8F-4E39-9F2A-931703906CE7@microsoft.com... > newbie question: > In a CASE statement, I would like the THEN clause to be the value of > another > column in the same table. Is this possible? I don't see any examples of > that > in BOL. > > What I am trying to do is something like: > CASE col1 > WHEN 1 THEN "okay" > WHEN 2 THEN p.LastName > END As result > but this syntax doesn't fly > > very grateful for the help > -- > sam
- Next message: Ramnadh: "RE: Performance Issue"
- Previous message: smk23: "CASE statement"
- In reply to: smk23: "CASE statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|