Link to home
Start Free TrialLog in
Avatar of abastien
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.
Avatar of digital_thoughts
digital_thoughts

You need to cast you DATEPART as a VARCHAR, here's another version that removes the time from a date:

CAST(CONVERT(VARCHAR(10), GETDATE(), 101) AS SMALLDATETIME)

This converts to a string and then back.
Avatar of abastien

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
Avatar of David Todd
David Todd
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked like a charm.  Thanks.