AdvenDatabase_2008

Embed Size (px)

Citation preview

  • 8/18/2019 AdvenDatabase_2008

    1/2

    use AdventureWorks2008R2

    SELECT ProductID,NameFROM Production.ProductWHERE Name LIKE 'B%';

    select * from Person.Person where Title is not null -- return rows with values ( not null)

    select Title,FirstName from Person.Person where Title is null -- null shoul not be checke with wildcards

    select Title,firstname,LastName from Person.Person where

    select Title,firstname,LastName from Person.Person where (Title ='ms.' or title ='ms.')

    ---======================select Name,ProductID from Production.Product

    select * from Production.ProductCostHistory

    select Name from Production.Product where (Name like 'b%') -- like operator returns data starting with b

    select ProductID,EndDate,ListPrice from Production.ProductListPriceHistory as h

    select P.Name,p.ProductID,h.ProductID,h.EndDate,h.ListPrice from Production.Product as Pinner join Production.ProductListPriceHistory as hon p.ProductID=h.ProductIDorder by p.Name,h.EndDate

    SELECT p.Name,h.EndDate,

    h.ListPriceFROM Production.Product AS pINNER JOIN Production.ProductListPriceHistory AS hON p.ProductID = h.ProductID ---NULL values in a descending sort are sor

    ted to the bottom.ORDER BY p.Name desc,h.EndDate desc; -- null values usally sorted first

    for ascending order

    -------------You want to sort by columns not returned by the query.SELECT p.Name,p.ColorFROM Production.Product AS pORDER BY p.Color;

    -----------You wish to present a result set to an application user N rows at a time.

    SELECT ProductID, NameFROM Production.ProductORDER BY NameOFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

    ---------

  • 8/18/2019 AdvenDatabase_2008

    2/2