Sql Tutorial Class


how to use not between in sql server

Not Between operator in SQL Server: It exclude the range value(s).


Syntax:
         Select [*|COLUMN_NAME,...] From [TABLE_NAME] Where COLUMN_NAME NOT 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.           
           [NOT BETWEEN]: SQL operator.


Here is a Table ItemDetails
ItemCodeItemNameManufactureCompanyItemSerialNoItemCategoryItemQuantityItemPriceProductCountry
1Samsung MobileSamsungS12345Mobile500240Korea
2Samsung ProSamsungSP1234Mobile100300Korea
3Samsung HeadphoneSamsungSH2345Headphone5050Korea
4iPhoneiPoneiP12345Mobile1000500United Stat
5Apple MobileAppleA12345Mobile200300United Stat
6Apple ComputerAppleA12343Computer200400United Stat
7Apple MacbookAppleAM2345Macbook50600United Stat
8Dell ComputerDELLD02345Computer200240United Stat
9Dell LaptopDELLDL2345Laptop30240United Stat
10Apple LaptopAppleAL2345Laptop500100United Stat
11Apple HeadphoneAppleAH2345Headphone5020United Stat
12Sony CameraSonySN2345Camera200240Japan
13Sony HeadphoneSonySNH345Headphone50050Japan
14Ascer ComputerAscerAC2345Computer100600China
16Borother PrinterBrotherB12345Printer200200China
17Ascer PrinterAscerAP2345Printer200150China
18Brother PhotocopyBrotherBP2345Printer20150China
19Brother Multi PrinterBrotherBM243PhotocopyNULLNULLIndia





Now,


Select ItemName,ManufactureCompany,ItemCategory,ItemPrice from ItemDetails Where ItemPrice not between '200' and '500'

Result:
ItemName ManufactureCompany ItemCategory ItemPrice
Samsung Headphone Samsung Headphone 50
Apple Macbook Apple Macbook 600
Apple Laptop Apple Laptop 100
Apple Headphone Apple Headphone 20
Sony Headphone Sony Headphone 50
Ascer Computer Ascer Computer 600
Ascer Printer Ascer Printer 150
Brother Photocopy Brother Printer 150









Select ItemName,ManufactureCompany,ItemCategory,ItemQuantity from ItemDetails where ItemQuantity Between '200' and '500'

Result:
ItemName ManufactureCompany ItemCategory ItemQuantity
Samsung Pro Samsung Mobile 100
Samsung Headphone Samsung Headphone 50
iPhone iPone Mobile 1000
Apple Macbook Apple Macbook 50
Dell Laptop DELL Laptop 30
Apple Headphone Apple Headphone 50
Ascer Computer Ascer Computer 100
Brother Photocopy Brother Printer 20







Not Between operator in SQL Server





Not Between operator in SQL Server
How to use not between in SQL server





No comments:

Post a Comment