473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Case when statement in where clause

When I execute the below query im getting the following error
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ')'.
Any one please give a solution to solve this.

In the below query dbo.FNSplitString is a user defined funcion to split the values in the string, since here project code parameter is in varchar but in the table it is integer datatype.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @prjcode VARCHAR(1000)
  2. SET @prjcode='0'
  3. --SET @prjcode='80,83,323'
  4. SELECT * 
  5.   FROM prolive.eld_pliv_emp_log epel
  6. WHERE epel.eld_shift_date BETWEEN '01-Jan-2012' AND '13-Jan-2012'
  7. AND epel.eld_prj_code IN (CASE WHEN @prjcode ='0' THEN epel.eld_prj_code ELSE (SELECT DATA FROM dbo.FNSplitString(@prjcode,',') ) )
Feb 15 '12 #1
1 1881
Rabbit
12,516 Expert Mod 8TB
You forgot the END statement of the CASE.
[code]
Expand|Select|Wrap|Line Numbers
  1. DECLARE @prjcode VARCHAR(1000)
  2. SET @prjcode='0'
  3. --SET @prjcode='80,83,323'
  4. SELECT * 
  5.   FROM prolive.eld_pliv_emp_log epel
  6. WHERE epel.eld_shift_date BETWEEN '01-Jan-2012' AND '13-Jan-2012'
  7. AND epel.eld_prj_code IN (CASE WHEN @prjcode ='0' THEN epel.eld_prj_code ELSE (SELECT DATA FROM dbo.FNSplitString(@prjcode,',') ) END)
Feb 15 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Largo SQL Tools | last post by:
Can anyone tell me if it's possible to use a Case statement in a Where clause, and if so, the proper syntax? J.R. Largo SQL Tools The Finest Collection of SQL Tools Available...
14
by: joshsackett | last post by:
I have a WHERE clause that could be an "=" or a "LIKE" depending upon if the passed variable is populated or not. I would like to know the best way to write the WHERE clause to make it dynamically...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
2
by: boa sema | last post by:
Way back when, and at least in version 7 IIRC, the query optimizer gave up when the where clause in a statement contained more than 4 search conditions. Does anyone know if such a limitation...
1
amitpatel66
by: amitpatel66 | last post by:
Hi, Is PLSQL Anonymous block allowed in CASE WHEN statement when CASE is used in SELECT statement. Check below code which executes but does not return anything: SELECT job, CASE WHEN job =...
1
by: martinley | last post by:
Hi, I have a table that contains data similar to the below, apologies for the table layout: employee_number balance_name balance_value a1 Gross Pay 100 a1 ...
2
by: vinayakkale2 | last post by:
Hi I am using a select query from front end to generate report in such a way that I should be able to get records of Table W which are present in Table Y The query which i am using is as follows: ...
4
by: laurenquantrell | last post by:
Is there an equivalant construction to the CASE WHEN statement that can be used in the WHERE clause? For example, this works: SELECT FirstName = CASE WHEN c.FirstName = 'Bob' THEN 'Robert'...
1
by: Charles Ndethi | last post by:
Hi I want to set the session id to a value after evaluating the request_time using a case when statement. here 's the table userinput_id session_id request_time ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.