December 20, 2006 at 8:54 pm
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
December 20, 2006 at 9:19 pm
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
December 20, 2006 at 9:25 pm
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply