Solved

How to 'select' specific values as a range in SQL?

Posted on 2007-04-06
2
982 Views
Last Modified: 2008-01-09
Hi, not sure if this is the correct category, but I want/would like to know how to create a where clause
whereby it selects values based on a 'range' or a 'set' of values.

I.e., say I have a set of products from 1-100. Is there anyway to do something like:

"Select * from productsTable where productRangeID is in {1,3,5,18,22,30,100}"

*instead* of having to do something like:

Select * from productsTable where (productRangeID ='1' OR productRangeID ='3' OR productRangeID ='5' ... etc, etc)?

Thanks!
0
Comment
Question by:cool12399
2 Comments
 
LVL 4

Accepted Solution

by:
opho earned 500 total points
ID: 18868092
Should be:

Select * from productsTable where productRangeID in(1,3,5,18,22,30,100)

--Steve
0
 
LVL 10

Author Comment

by:cool12399
ID: 18868492
Ah excellent! perfect, thanks! :) It saves me a lot of programming! ;)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

815 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

9 Experts available now in Live!

Get 1:1 Help Now