Solved

Case Statement errors.

Posted on 2007-11-15
4
199 Views
Last Modified: 2010-03-20
I keep getting errors on this Case Statement.  
here is my statement:

DECLARE @startdate varchar(10)
CASE
WHEN
RP.Current_Run_Date = Select max(crtDate) from [Transaction]..NARRStatusHistory  
 THEN @startDate = RP.Previous_run_Date
from Reports.dbo.tblRpt_Param RP
END

Print '@startdate'

Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'CASE'.
Server: Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'THEN'.


0
Comment
Question by:donnie91910
4 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20293260

declare @startDate datetime
SELECT @startDate = 
CASE
WHEN
RP.Current_Run_Date = (Select max(crtDate) from [Transaction]..NARRStatusHistory)  
 THEN RP.Previous_run_Date
END
from Reports.dbo.tblRpt_Param RP

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 20293596
what about this:

DECLARE @startdate datetime
DECLARE @maxdate datetime

SELECT @maxdate = max(crtDate) from [Transaction]..NARRStatusHistory  

SELECT @startdate =
CASE WHEN RP.Current_Run_Date = @maxdate
   THEN @startDate = RP.Previous_run_Date
END
FROM Reports.dbo.tblRpt_Param RP

Print @startdate
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20999831
Forced accept.

Computer101
EE Admin
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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