Please explain.

  • Unless there is a syntax error in the CAST Statment below then why does CAST not work and CONVERT does?

    SELECT OrderID, CAST(DATEPART(day, OrderDate) AS VARCHAR(5)) + '/' + CAST(DATEPART(Month, OrderDate), AS VARCHAR(5))

    FROM Orders

    SELECT OrderID, CONVERT(VARCHAR(5), DATEPART(day, OrderDate)) + '/' + CONVERT(VARCHAR(5), DATEPART(Month, OrderDate)) AS 'Day/Month'

    FROM Orders


    Kindest Regards,

  • Actually both queries are correct but in first query by mistake you have typed comma before AS(shown in RED), delete that comma & the query gives the same result.

    SELECT OrderID, CAST(DATEPART(day, OrderDate) AS VARCHAR(5)) + '/' + CAST(DATEPART(Month, OrderDate), AS VARCHAR(5))

    FROM Orders

     

     

  • Ok Thanks.


    Kindest Regards,

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply