Solved

How can i rewrite the following SQL statement?

Posted on 2011-02-28
4
1,465 Views
Last Modified: 2012-06-21
How can i rewrite the WHERE clause with out using the use of IN special operator:
WHERE L_ST IN (‘WA’, ‘ID’, ‘NY’)
0
Comment
Question by:checkmofoshoduno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 34995922
WHERE L_ST =‘WA’ or L_ST= ‘ID’ or  L_ST='NY’
0
 
LVL 8

Expert Comment

by:raulggonzalez
ID: 34997631
You can use OR like mayank_joshi said, but if I was you, I'd leave the IN ( ) ...

It's easier to read and will not mess with any other condition you may add ( you will need to use parenthesis or similar.)  


Cheers
0
 
LVL 6

Accepted Solution

by:
anushahanna earned 500 total points
ID: 35003666
technically, union is also another option.

select.........WHERE L_ST =‘WA’
union
select.........WHERE L_ST =‘ID’
union
select.........WHERE L_ST =‘NY’
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 35005676

@anushahanna
   union all  probably

 


What are you actually asking us...
why do you need to re-write the statement...

as with most sql comparisons if the set of data is going to be repeatedly used then it should
 be set up on a table and reference (via a Join) that way....

create table State_groups (collection_name char(10) not null, grouping_name char(10) not null,
       State_alias cjar(2) not null, primary key (collection_name,grouping_name,state_alias))

e.g.  'UPSPOSTRATE','MIDWEST','WA'
           ....


from Yourtable as x
 inner join state_groups as s
  on x.l_st- s.state_alias
 and s.collection_name='UPSPOSTRATE'
 and s.grouping_name='MIDWEST'

 
   

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 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