Monday, February 23, 2015

#20. Write a SELECT statement that returns these columns from the Orders table

#20.  Write a SELECT statement that returns these columns from the Orders table:
A column that uses the CONVERT function to return the OrderDate column in this format: MM/DD/YYYY. In other words, use two-digit months, days, and years and separate each date component with slashes
A column that uses the CONVERT function to return the OrderDate column with the date, and the hours and minutes on a 12-hour clock with an am/pm indicator
A column that uses the CONVERT function to return the OrderDate column with 2-digit hours, minutes, and seconds on a 24-hour clock. Use leading zeros for all date/time components.


2 comments:

  1. I do not see this question and you do not have a search button or contact page so I am asking here. Can you possibly help with this question from Murach (MyGuitarShop). I am struggling in class because my teacher does not teach. He just reads from the book and has us follow the book exactly no extra. So here it is

    #7 Chapter 4
    Use the UNION operator to generate a result set consisting of three columns from the Orders table:
    ShipStatus---------A calculated column that contains a value of --------------------SHIPPED or NOT SHIPPED
    OrderID------------The OrderId column
    OrderDate----------The OrderDate column

    If the order has a value in the ShipDate column, the ShipStatus column should contain a value of SHIPPED. Otherwise, it should contain a value of NOT SHIPPED

    Sort the final result set by OrderDate

    Well if you respond, thank you very much!

    ReplyDelete
    Replies
    1. SELECT OrderID, ORderDate, 'Shipped' AS ShipStatus
      From Orders
      WHERE ShipDate IS NOT NULL
      UNION
      SELECT OrderId,OrderDate, 'Not Shipped' AS ShipStatus
      FROM Orders
      Where ShipDate IS NULL

      Delete