abastien
asked on
Transact-SQL string concatenation select statement error
I have a Transact-SQL stored procedure, I have written, which returns results that include a datetime field. I am trying to use the DATEPART() function to parse out the field, so that the date that is output does not include the time (i.e...MM/DD/YYYY). I am using the + operater to try to concatenate a forward slash, which I have in single quotes, to a column that has returned using the DATEPART() function. I have tried using various methods, but can't get the select query to run without an error. When I try to run (select (DATEPART(m, dateColumn) + '/'), otherColumn from Table) I get the following error message. Syntax error converting the varchar value '/' to a column of data type int.
ASKER
Thanks for the suggestion. That did remove the values for the time, but now it returns a value of 00:00:00 after the date. Is there a way to strip that out completely?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm. Thanks.
CAST(CONVERT(VARCHAR(10), GETDATE(), 101) AS SMALLDATETIME)
This converts to a string and then back.