Solved

Case Statement errors.

Posted on 2007-11-15
4
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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