Monday, April 2, 2012

Simple Selects

Use Automart;
/*this is a multline
comment */

--simple select
Select Lastname, Firstname from Person

--select with a wildcare
Select * From Person
--alias
Select Lastname as [Last Name], FirstName as [First Name]
From Person

Select Lastname [Last Name], FirstName  [First Name]
From Person

Select Lastname as "Last Name", FirstName as "First Name"
From Person

Select Lastname Last, FirstName First 
From Person

--concatination
Select LastName + ', ' + Firstname [Person Name]
From Person

--order by
Select Lastname, Firstname
From Person
order by lastname Desc, firstname asc

Select top 5 Lastname from Person
order by lastname

Select * From Person
Where LastName='Smith'

Select * from Person
Where LastName Like 'S%'

Select * From Employee.VehicleService
Where ServiceDate between '4/1/2010' and '4/30/2010'

Select * From Employee.VehicleService
Where ServiceDate >= '4/1/2010' and ServiceDate <= '4/30/2010'

Select * From Customer.AutoService
Where ServicePrice > 100

Select * From Employee
Where SupervisorID is not null

Select * From Employee
Where SupervisorID = null

No comments:

Post a Comment