Solved

How can i rewrite the following SQL statement?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now