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

IF ELSE to cause a WHERE

What it boils down to is such:

IF(Condition)
WHERE Column_Name = 'x'
ELSE
I don't want a 'WHERE'

I had this for a while, but it's not working the way I want due to the fact that there is no else statement:

WHERE Column_Name = CASE
WHEN(Condition != 'All') Then 'x' end
Jan 11 '12 #1

✓ answered by ck9663

It's called conditional WHERE clause. To do what you are trying to accomplish, you have to remember that an "always true" condition is as if there's no where.

So try something like...

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE Column_Name = case when (Condition) = True then 'x' else Column_Name end
  3.  
  4.  
Now, be careful on reversing this condition and consider NULL.

Happy Coding!!!


~~ CK

1 1310
ck9663
2,878 Expert 2GB
It's called conditional WHERE clause. To do what you are trying to accomplish, you have to remember that an "always true" condition is as if there's no where.

So try something like...

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE Column_Name = case when (Condition) = True then 'x' else Column_Name end
  3.  
  4.  
Now, be careful on reversing this condition and consider NULL.

Happy Coding!!!


~~ CK
Jan 11 '12 #2

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

Similar topics

27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
2
by: Nat | last post by:
Hi there, I have code as following but it returns error Error Type: Microsoft VBScript compilation (0x800A03F6) Expected 'End' /urbisjhdintranet/metadata/resultList.asp, line 324 which is the...
7
by: jcochran | last post by:
What would be the correct way of writing a sql select state with where clause while also using IF ELSE. I am using T-SQL and I cannot get it to work. I probably have the syntax wrong. I want to...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) {...
2
by: MCOOP | last post by:
Is there a way to have a declare variable (@where) be used as the WHERE clause in a stored procedure? The reason I ask is that I'm trying to use one sql statement for several possible WHERE...
28
by: davinski | last post by:
So thanks to another member here I got my view sorted out :D but now that I've begun to write my stored proc I've ran into another problem! Basically, my stored proc takes about 30 variables and...
2
by: Lawrence | last post by:
Hi I have only begun to look into ASP due to an assignments requirements (I usually code in PHP), one feature in PHP is to be able to do an if...else statement, where if a certain statement is...
6
by: elbatz | last post by:
How can i make an if else statement where the condition is in sql.for example:\ if data exist then delete the old and insert the new data else insert new data. Thank you.
0
by: =?ISO-8859-1?Q?G=F6ran_Andersson?= | last post by:
MC wrote: No, the problem is not with the compiler, but with the poster. What he describes does not happen, he just invents things like this to troll the newsgroup. -- Göran Andersson
5
kirubagari
by: kirubagari | last post by:
* * * Function Name : int Generate_PR_Report * Program: * Purpose: -Gather data on problematic lot and put into the log file for user reference. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.