Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Case Statement errors.

Posted on 2007-11-15
4
Medium Priority
?
203 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 1000 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 1000 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…
Suggested Courses

715 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