Solved

Incorrect syntax near the keyword 'BETWEEN'

Posted on 2012-03-27
3
1,135 Views
Last Modified: 2012-03-27
I could not figure out what is wrong with my syntax:

declare @StartDate DateTime,
@EndDate DateTime,
@BranchName varchar (20),
@ReportType varchar(50)
set @StartDate='02/1/2012'
set @EndDate='02/29/2012'

SELECT [Branch Name], [Stage Number],
[Not Signed Application Date],
[Fund Date],
[UW Approve Date]
FROM          tablename
WHERE        
 [Branch Name] in(@BranchName)AND ([Stage Number] >= 20)  AND
case
 WHEN @ReportType=a'
    THEN [Not Signed Application Date] BETWEEN @StartDate AND @EndDate
WHEN @ReportType='b'
  THEN [Fund Date] BETWEEN @StartDate AND @EndDate
WHEN @ReportType='c'
   THEN [UW Approve Date] BETWEEN @StartDate AND @EndDate
END


Thanks!
0
Comment
Question by:sharon2011
  • 2
3 Comments
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 37771492
The THEN and ELSE results must be a single *value* (or an expression that ultimately yields a single value), NOT a keyword or other multi-word result.
0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 37771501
Therefore, change it to this:


case
 WHEN @ReportType=a' AND [Not Signed Application Date] BETWEEN @StartDate AND @EndDate THEN 1
WHEN @ReportType='b' AND [Fund Date] BETWEEN @StartDate AND @EndDate THEN 1
WHEN @ReportType='c' AND [UW Approve Date] BETWEEN @StartDate AND @EndDate THEN 1
ELSE 0
END = 1
0
 

Author Closing Comment

by:sharon2011
ID: 37771583
It works. Thank you very very much.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Minus first query 1 36
SQL compatability in SQL 2016 2 31
Columnstore Indexes - real-time operational analytics 1 11
Extract string portion 2 14
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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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