Solved

Case Statement errors.

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do i get a breakdown of totals by age range? 10 23
Sql Stored Procedure field variable 17 31
string fuctions 4 26
Mysql Left Join Case 10 56
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

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