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

SQL 2 tables ask

I need an IF statment at SQL

I have 2 tables (names A B)
i need (In SQL stetments) to search from table A if rows in table B
with this conditions:

if B.col1=1 or B.col1=6 then search all row (1=1)
otherwise select A.col1=B.col1

this select is part of a big select from A,B tables

Best Regards
Yuval
Jul 23 '05 #1
2 1015
moshe (yu******@gmail.com) writes:
I need an IF statment at SQL

I have 2 tables (names A B)
i need (In SQL stetments) to search from table A if rows in table B
with this conditions:

if B.col1=1 or B.col1=6 then search all row (1=1)
otherwise select A.col1=B.col1

this select is part of a big select from A,B tables


The CASE expression might be useful:

...
AND a.col1 = CASE WHEN b.col1 IN (1, 6) THEN b.col1 ELSE a.col1 END
...
If this does not cut it, you will get better help if you include more
information. The standard recommendatation is to include:

o CREATE TABLE statements for your tables (possibly simplified)
o INSERT statement with sample data.
o The desired result given the sample.
o A short description of the underlying business problem.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
> AND a.col1 = CASE WHEN b.col1 IN (1, 6) THEN b.col1 ELSE a.col1 END

oops, wrong way round

AND a.col1 = CASE WHEN b.col1 IN (1, 6) THEN a.col1 ELSE b.col1 END

depending on nulls in a.col1, this may also be useful

AND (a.col1 = b.col1 OR b.col1 IN (1,6))

Mr Tea

"Erland Sommarskog" <es****@sommarskog.se> wrote in message
news:Xn**********************@127.0.0.1...
moshe (yu******@gmail.com) writes:
I need an IF statment at SQL

I have 2 tables (names A B)
i need (In SQL stetments) to search from table A if rows in table B
with this conditions:

if B.col1=1 or B.col1=6 then search all row (1=1)
otherwise select A.col1=B.col1

this select is part of a big select from A,B tables


The CASE expression might be useful:

...
AND a.col1 = CASE WHEN b.col1 IN (1, 6) THEN b.col1 ELSE a.col1 END
...
If this does not cut it, you will get better help if you include more
information. The standard recommendatation is to include:

o CREATE TABLE statements for your tables (possibly simplified)
o INSERT statement with sample data.
o The desired result given the sample.
o A short description of the underlying business problem.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
1
by: Shelby | last post by:
Problem: My company generates its own data export from a propietary database. These (free) tables can be read in C#.NET using a Visual FoxPro driver (vfpoledb). I can read each of the six tables...
59
by: phil-news-nospam | last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats the idea that using tables in CSS is not something that should be done because IE doesn't support it. Of course I'm not happy...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
4
by: db2admin | last post by:
Hello, I want to plan rearranging tables in our database according to business areas. say all tables in business area A will be in seperate tablespace or tablespaces. I am planning to monitor...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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.