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
 Site Related Forums
 Article Discussion
 CASE Question

Author  Topic 

IHaveNoClue
Starting Member

2 Posts

Posted - 2003-02-10 : 15:16:53
How do you use CASE to affect values outside the clause?

Example:
SELECT
tblClientMaster.sName AS 'ClientName',
Case InvoiceTransactionType.sName
WHEN 'Void' Then
VoidReason.sName = " ",
VoidReason.sDescription = " ",
VoidReason.iSort = " "
Else
VoidReason.sName AS VoidReasonName,
VoidReason.sDescription AS VoidReasonDescription,
VoidReason.iSort AS VoidReasonNumber
End

Any ideas?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-02-10 : 16:13:17
you need to repeat the CASE expression 3 times.

SELECT
tblClientMaster.sName AS 'ClientName',
Case sName WHEN 'Void' THEN " " ELSE sName END as sName,
CASE sName WHEN 'Void' THEN " " ELSE sDescription END as sDescription,
CASE sName WHEN 'Void' THEN " " ELSE iSort END as iSort
FROM
...

Also, note that naming fields with prefixes based on their datatype isn't really the "hip" thing to do in SQL now-a-day .....

- Jeff
Go to Top of Page

IHaveNoClue
Starting Member

2 Posts

Posted - 2003-02-11 : 08:28:12
quote:

you need to repeat the CASE expression 3 times.

SELECT
tblClientMaster.sName AS 'ClientName',
Case sName WHEN 'Void' THEN " " ELSE sName END as sName,
CASE sName WHEN 'Void' THEN " " ELSE sDescription END as sDescription,
CASE sName WHEN 'Void' THEN " " ELSE iSort END as iSort
FROM
...

Also, note that naming fields with prefixes based on their datatype isn't really the "hip" thing to do in SQL now-a-day .....

- Jeff



Go to Top of Page
   

- Advertisement -