Solved

How can i rewrite the following SQL statement?

Posted on 2011-02-28
4
1,433 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now