Between Operator in SQL Server:
Syntax:
Select [*|COLUMN_NAME,...] From [TABLE_NAME] Where COLUMN_NAME BETWEEN 'VALUE' AND 'VALUE2'
Description:
Select: SQL Keyword.
* | COLUMN_NMME: All or specific column name.
From: SQL Keyword.
TABLE_NAME: Name of table.
Where: SQL keyword.
AND: SQL operator.
VALUE.. : User define value.
[BETWEEN]: SQL operator.
[BETWEEN]: SQL operator.
Here is a Table ItemDetails
| ItemCode | ItemName | ManufactureCompany | ItemSerialNo | ItemCategory | ItemQuantity | ItemPrice | ProductCountry |
| 1 | Samsung Mobile | Samsung | S12345 | Mobile | 500 | 240 | Korea |
| 2 | Samsung Pro | Samsung | SP1234 | Mobile | 100 | 300 | Korea |
| 3 | Samsung Headphone | Samsung | SH2345 | Headphone | 50 | 50 | Korea |
| 4 | iPhone | iPone | iP12345 | Mobile | 1000 | 500 | United Stat |
| 5 | Apple Mobile | Apple | A12345 | Mobile | 200 | 300 | United Stat |
| 6 | Apple Computer | Apple | A12343 | Computer | 200 | 400 | United Stat |
| 7 | Apple Macbook | Apple | AM2345 | Macbook | 50 | 600 | United Stat |
| 8 | Dell Computer | DELL | D02345 | Computer | 200 | 240 | United Stat |
| 9 | Dell Laptop | DELL | DL2345 | Laptop | 30 | 240 | United Stat |
| 10 | Apple Laptop | Apple | AL2345 | Laptop | 500 | 100 | United Stat |
| 11 | Apple Headphone | Apple | AH2345 | Headphone | 50 | 20 | United Stat |
| 12 | Sony Camera | Sony | SN2345 | Camera | 200 | 240 | Japan |
| 13 | Sony Headphone | Sony | SNH345 | Headphone | 500 | 50 | Japan |
| 14 | Ascer Computer | Ascer | AC2345 | Computer | 100 | 600 | China |
| 16 | Borother Printer | Brother | B12345 | Printer | 200 | 200 | China |
| 17 | Ascer Printer | Ascer | AP2345 | Printer | 200 | 150 | China |
| 18 | Brother Photocopy | Brother | BP2345 | Printer | 20 | 150 | China |
| 19 | Brother Multi Printer | Brother | BM243 | Photocopy | NULL | NULL | India |
Now,
Select ItemName,ManufactureCompany,ItemCategory,ItemPrice from ItemDetails Where ItemPrice between '200' and '500'
Result:
| ItemName | ManufactureCompany | ItemCategory | ItemPrice |
| Samsung Mobile | Samsung | Mobile | 240 |
| Samsung Pro | Samsung | Mobile | 300 |
| iPhone | iPone | Mobile | 500 |
| Apple Mobile | Apple | Mobile | 300 |
| Apple Computer | Apple | Computer | 400 |
| Dell Computer | DELL | Computer | 240 |
| Dell Laptop | DELL | Laptop | 240 |
| Sony Camera | Sony | Camera | 240 |
| Borother Printer | Brother | Printer | 200 |
Select ItemName,ManufactureCompany,ItemCategory,ItemQuantity from ItemDetails where ItemQuantity Between '200' and '500'
Result:
| ItemName | ManufactureCompany | ItemCategory | ItemQuantity |
| Samsung Mobile | Samsung | Mobile | 500 |
| Apple Mobile | Apple | Mobile | 200 |
| Apple Computer | Apple | Computer | 200 |
| Dell Computer | DELL | Computer | 200 |
| Apple Laptop | Apple | Laptop | 500 |
| Sony Camera | Sony | Camera | 200 |
| Sony Headphone | Sony | Headphone | 500 |
| Borother Printer | Brother | Printer | 200 |
| Ascer Printer | Ascer | Printer | 200 |
Between operator in SQL Server
Between operator in SQL Server

No comments:
Post a Comment