Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can i rewrite the following SQL statement?

Posted on 2011-02-28
4
Medium Priority
?
1,490 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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