Skip to main content

SQL Where Queries : Day 2 #100Days of SQL

Today, I am going to share about Where clause usages in SQL Query using Microsoft SQL server and AdventureWorks Database.

We Will gonna use "Production.Product" Table in this examples,
In this blogpost will see about where clause with other operators such as and, or, like, not null, null 
Initially we will explore about Simple SQL where clause queries here,
Later I will update more complex SQL where clause queries in future days.

At First we will see the normal Query with resultsets

select * from Production.Product 

-- returned 504 rows of data



In this below Query we will see about Safety Stock level value below 1000

-- where query for SafetyStock level below 1000

select Production.Product.ProductID, 

       Production.Product.Name,

   Production.Product.SafetyStockLevel

from   Production.Product

where  Production.Product.SafetyStockLevel < 1000 


 

In this below query will explore safety stock level values are above 600\

-- where query for SafetyStock level above 600

select Production.Product.ProductID, 

       Production.Product.Name,

   Production.Product.SafetyStockLevel

from   Production.Product

where  Production.Product.SafetyStockLevel > 600 



In this Below query where safety stock level values below 500 or above 800

-- where query for SafetyStock level above 800 or below 500

select Production.Product.ProductID, 
       Production.Product.Name,
   Production.Product.SafetyStockLevel
from   Production.Product
where  Production.Product.SafetyStockLevel < 500 or  
       Production.Product.SafetyStockLevel > 800


In this below query, same safety stock level values are above 100 and below 800 

-- where query for SafetyStock level above 100 and below 800
select Production.Product.ProductID, 
       Production.Product.Name,
   Production.Product.SafetyStockLevel
from   Production.Product
where  Production.Product.SafetyStockLevel > 100 and  
       Production.Product.SafetyStockLevel < 800


In this below query, using like operator in where clause First we will see about starts with [anycharacters]% wildcards

-- where query for SafetyStock Product Number starts with C character like operator
select Production.Product.ProductID, 
       Production.Product.Name,
   Production.Product.ProductNumber,
   Production.Product.SafetyStockLevel
from   Production.Product
where  Production.Product.ProductNumber like 'C%'


In this below query, using like operator in where clause, here we will see about ends with %[anycharacters] wildcards

-- where query for SafetyStock Product Number ends with 7 character like operator
select Production.Product.ProductID, 
       Production.Product.Name,
   Production.Product.ProductNumber,
   Production.Product.SafetyStockLevel
from   Production.Product
where  Production.Product.ProductNumber like '%7'

In below queries, like between, not null, null , and, or operators are utilized

-- where query for SafetyStock Product contains 8 character in a string with like operator anywhere starting, ending, in between

select Production.Product.ProductID, 

       Production.Product.Name,

   Production.Product.ProductNumber,

   Production.Product.SafetyStockLevel

from   Production.Product

where  Production.Product.ProductNumber like '%8%'


-- where query with not null
select * from Production.Product where Color is not null

-- where query with null
select * from Production.Product where Color is null

-- where between and 
select * from Production.Product where ReorderPoint between 10 and 600


-- where between and like operator 

select * from Production.Product where ProductNumber like 'C%' and ReorderPoint between 10 and 600


-- where between or like operator
select * from Production.Product where ProductNumber like 'C%' or ReorderPoint between 10 and 600



 - Will update more complex where clause queries, stay connected 

Comments

Popular posts from this blog

"How to maintain or retain tabs in same tab after button click events or postback?" using JQuery in ASP.NET C#

In this post I'll share an details about " How to maintain or retain tabs in same tab after button click events or postback? " Step 1: you need to download Jquery and JQueryUI Javascript libraries from this site http://jqueryui.com/ Step 2: As usually you can create ASP.NET website from Visual Studio IDE and add Jquery and JqueryUI plugins in the header section of aspx page. Step 3: Add HiddenField control inside aspx page which is very useful to retain tab in same page Step 4: Use the HiddenField ID in Jquery code to indicate that CurrentTab Index Step 5: In code Behind, using Enumerations concept give the tab index values as user defined variable  Step 6: Use the Enum values in every Button click events on different tabs to check that tab could be retained in the same tab Further, Here I'll give the code details and snap shot pictures, 1. Default.aspx: Design Page First Second Third ...

Guidewire Related Interview Question and answers part 1

common Guidewire questions and answers 20 Guidewire BC Q&A Top 100 Guidewire Interview FAQ Guidewire Claimcenter 20 Interview Questions Guidewire Rating concepts

Login and Registration forms in C# windows application with Back end Microsoft SQL Server for data access

In this article, I'm gonna share about how to make login and register form with MS SQL database; 1. Flow Chart Logic 2. Normal Features 3. Form Designs Login Form Design Sign in Form Design Password Retrieve Form 4. Database Design and SQL queries and Stored Procedure Create new Database as "schooldata" create table registerdata (  ID int identity,  Username nvarchar(100),  Password nvarchar(100),  Fullname  nvarchar(100),  MobileNO nvarchar(100),  EmailID nvarchar(100)  ) select * from registerdata create procedure regis (  @Username as nvarchar(100),  @Password as nvarchar(100),  @Fullname as nvarchar(100),  @MobileNO as nvarchar(100),  @EmailID as nvarchar(100)  ) as begin insert into registerdata (Username, Password, Fullname, MobileNO,EmailID) values (@Username, @Password, @Fullname, @MobileNO, @EmailID) ...