Wednesday, 20 April 2011

SQL Between

The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.

Syntax

  SELECT column_name(s)
  FROM table_name
  WHERE column_name
  BETWEEN value1 AND value2



The "Custmast" Table  ( Note Date Format ( MM/DD/YYYY)


custcode
Date
custname
city
rate
1
02/22/2008
Siva
Srivilliputtur
70
2
06/08/2009
Bala
Sivakasi
56
3
02/15/2010
Kanna
Madurai
200
4
02/04/2011
Vijay
Chennai
30
5
07/08/2011
Kodee
Sandnes
80
5
08/06/2012
Kodee
Srivilliputtur
30

Example: 1
SELECT     *
FROM         custmast
WHERE     Date BETWEEN '01/01/2009' and '6/08/2011'

Output :
custcode
Date
custname
city
rate
2
06/08/2009
Bala
Sivakasi
56
3
02/15/2010
Kanna
Madurai
200
4
02/04/2011
Vijay
Chennai
30

Example: 2
SELECT     *
FROM         custmast
WHERE     custcode BETWEEN 1 and  3

Output :
custcode
Date
custname
city
rate
1
02/22/2008
Siva
Srivilliputtur
70
2
06/08/2009
Bala
Sivakasi
56
3
02/15/2010
Kanna
Madurai
200

 Share This Post


Friendly Learn Translate to Tamil

Smilely

Services

© 2014