Solved

Help with SQL CASE SELECT

Posted on 2010-11-30
2
256 Views
Last Modified: 2012-05-10
See my code below.. I want the code to put the field sComment to stated below if the berrorflag is 0 otherwise I want the sComment to have something else.. The second "case" keword is highlighted and I'm not sure what I'm doing wrong
CASE 
	WHEN  css.bErrFlag =0
     CASE (css.sDeliveryMethod)
	  WHEN 'fax'    THEN 'Web customer requests the listed invoice number: ' + (css.sTransactionNo) + ' to be sent via: ' 
		    + (css.sDeliveryMethod) + ' to ' + COALESCE(css.sPhone_Fax, '') 
	  WHEN 'email'  THEN 'Web customer requests the listed invoice number: ' +  (css.sTransactionNo) + ' to be sent via: ' 
		    + (css.sDeliveryMethod) + ' to ' + COALESCE(css.semail, '') 
	  WHEN 'e-mail' THEN 'Web customer requests the listed invoice number: ' + (css.sTransactionNo) + ' to be sent via: ' 
		    + (css.sDeliveryMethod) + ' to ' + COALESCE(css.semail, '') 
	  WHEN 'mail'   THEN 'Web customer requests the listed invoice number:  ' +  (css.sTransactionNo) + ' to be sent via: ' 
		    + (css.sDeliveryMethod) + ' to ' + COALESCE(css.saddress1, '') + '; ' + COALESCE(css.sAddress2, '') 
		    + '; ' + COALESCE(css.scity, '') + ', ' + COALESCE(css.sstate, '') + '  ' + COALESCE((right(css.szip,5)), '') 
     ELSE 'Customer requested invoices be sent and did not choose a delivery method. '
     END 
  ELSE 'Error in case:'+(css.sErrMsg)
  END sComment,

Open in new window

0
Comment
Question by:cheryl9063
2 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 34239579
You need a THEN after the first CASE:

CASE WHEN  css.bErrFlag =0 THEN
0
 
LVL 1

Author Closing Comment

by:cheryl9063
ID: 34239589
Perfect thanks so much!!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tempdb log keep growing 7 43
RAISERROR WITH NOWAIT 2 24
How can I find this data? 3 23
SQL syntax question 6 36
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question