Solved

Case Statement errors.

Posted on 2007-11-15
4
196 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 142

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now