473,423 Members | 1,786 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,423 software developers and data experts.

CASE Expression in WHERE

1
I know you should be able to use a Case Expression within a WHERE Clause but I am having some trouble.

The user will be able to select what type of Operator they want so they can search client balance information...because of this I need 1 clause for the BETWEEN and one for all the others (>=, =, <= , ect). I am receiving error at line 7 "Incorrect syntax near the keword THEN which doesn't help much.

DECLARE @Operator VARCHAR(10)
SET @Operator = '>'

SELECT Balance
FROM ClientInformation
WHERE @Operator = CASE WHEN 'BETWEEN'
THEN CAST(Balance AS MONEY) BETWEEN 1 and 2
ELSE CAST(Balance AS MONEY) @Operator 30
END

Can someone help me out here
Mar 30 '10 #1
1 1217
ck9663
2,878 Expert 2GB
Try something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE (@Operator = 'BETWEEN' and CAST(Balance AS MONEY) BETWEEN 1 and 2) or
  3.  (@Operator = '>'and CAST(Balance AS MONEY) > 30
  4. ) or
  5. (@Operator = '<'and CAST(Balance AS MONEY) < 30
  6. )
  7.  
  8.  
Happy Coding!!!

~~ CK
Mar 31 '10 #2

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

Similar topics

3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
4
by: Seenu | last post by:
I'm experiencing some puzzling behaviour with some of my UDFs when declaring them as ATOMIC.. Basically I'm invoking another UDF (which uses some Java code) in one branch of a CASE statment, and...
6
by: Antanas | last post by:
How can I make Case expression not to execute ADDID() when it does not satisfy requirements? Right now it executes function even if requirments are not met. SELECT ADDID(), CASE WHEN 'A' IS...
5
by: DaaaDaaa | last post by:
Hi, Here's what I'd like to do: table (Orders) has fields of Processed, Paid (both of boolean yes|no) etc, I want to return a count of of Total number of Orders, Number of Processed vs. Number...
8
by: Jeff Gilbert | last post by:
Hello all. I'd appreciate some help with this one: First the DDL: CREATE TABLE ( NOT NULL , NULL , NOT NULL , (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , NOT NULL...
14
by: Daron | last post by:
I am doing so data validation, and need to check if a filed contains a valid date in the format of "YYYY-MM-DD" I would like to know if it is possible to convert this series of If's to a Select...
7
by: mandible | last post by:
Hello I'm trying to have some control on how my data is ordered depending on an input parameter my question is in a stored procedure how can I do something like this at the end of my...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.