473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Give a range in a query

hi..

i want to kow wether can we give a range in sql.
maens i want to get the values in field where one period to another period.
example:ther is two fields in the table period and data. i want to get all the values in data field acccording to given period value (like 1 to 3) how can i do this??

thank you in advance
Dec 15 '09 #1

✓ answered by nbiswas

Are you looking for this

Sample data

Expand|Select|Wrap|Line Numbers
  1. declare @t table(period int, data varchar(20))
  2. insert into @t 
  3.     select 1,'data1' union all select 2,'data2' union all 
  4.     select 3,'data3' union all select 4,'data4' union all 
  5.     select 5,'data5' union all select 6,'data6' union all 
  6.     select 7,'data7' union all select 8,'data8' union all 
  7.     select 9,'data9' union all select 10,'data10' 
  8. select * from @t
Query 1:

Expand|Select|Wrap|Line Numbers
  1. select data from @t where period between 1 and 3
Query 2:

Expand|Select|Wrap|Line Numbers
  1. select data from @t where period>= 1 and period<=3
Output:

data
Expand|Select|Wrap|Line Numbers
  1. data1
  2. data2
  3. data3
I am selecting data between the period 1 & 3

Hope this helps.

2 2477
nbiswas
149 100+
Are you looking for this

Sample data

Expand|Select|Wrap|Line Numbers
  1. declare @t table(period int, data varchar(20))
  2. insert into @t 
  3.     select 1,'data1' union all select 2,'data2' union all 
  4.     select 3,'data3' union all select 4,'data4' union all 
  5.     select 5,'data5' union all select 6,'data6' union all 
  6.     select 7,'data7' union all select 8,'data8' union all 
  7.     select 9,'data9' union all select 10,'data10' 
  8. select * from @t
Query 1:

Expand|Select|Wrap|Line Numbers
  1. select data from @t where period between 1 and 3
Query 2:

Expand|Select|Wrap|Line Numbers
  1. select data from @t where period>= 1 and period<=3
Output:

data
Expand|Select|Wrap|Line Numbers
  1. data1
  2. data2
  3. data3
I am selecting data between the period 1 & 3

Hope this helps.
Dec 15 '09 #2
thank you it worked nicely.
Dec 15 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dan | last post by:
I am a relatively new user on Oracle 9.2.0.1 and I am having trouble performance tuning this production database. I am running a large query that joins two tables, document(3 mil) and entity(9...
3
by: aroy | last post by:
Hi, Need help in optimizing a query in SQL Server. Following is the problem statement. There are two tables; 1st table (t1) has a KEY ( char(8) ) column, with a clustered index. this is not...
4
by: Jorey Bump | last post by:
I can retrieve today's date: mysql> SELECT CURDATE() AS begin; +------------+ | begin | +------------+ | 2005-06-01 | +------------+ 1 row in set (0.00 sec)
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
1
by: isetea | last post by:
Hi, I want to create a from where user can select from a date range / type in a date range to get only data from an underlying query within this range. This should overwrite the existing criteria...
4
by: Tess2819 | last post by:
Hi Everyone, This is my first topic so I hope you can help. I have searched but can't seem to find what I am looking for, so here it is. I want to create a query using design view in...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
12
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.