Format date and then convert to string

I am trying to compile a string as part of a select statement in SQL which converts a date time, firstly into the desired date format (103) and then into a VARCHAR for use in the string.

The following does not work:

dbo.SHOP_RESOURCE.DESCRIPTION + '-' + dbo.LABOR_TICKET.WORKORDER_BASE_ID + '-' + CONVERT (varchar, dbo.LABOR_TICKET.OPERATION_SEQ_NO) + '-' + dbo.WORK_ORDER.PART_ID + '-' + CAST(CONVERT (DATETIME, dbo.LABOR_TICKET.TRANSACTION_DATE, 103) AS VARCHAR)

Would anyone be able to help me out on this one? I'm sure it's going to be something really easy!

Thanks

Steve
LVL 3
FMabeyAsked:
Who is Participating?
 
OMC2000Commented:
dbo.SHOP_RESOURCE.DESCRIPTION + '-' + dbo.LABOR_TICKET.WORKORDER_BASE_ID + '-' + CONVERT (varchar, dbo.LABOR_TICKET.OPERATION_SEQ_NO) + '-' + dbo.WORK_ORDER.PART_ID + '-' + CONVERT (VARCHAR(10), dbo.LABOR_TICKET.TRANSACTION_DATE, 103)
0
 
Mark WillsTopic AdvisorCommented:
Dont have to CAST as well as CONVERT

Just use CONVERT(varchar(10),dbo.LABOR_TICKET.TRANSACTION_DATE, 103)
0
 
FMabeyAuthor Commented:
I knew it would be something simple! Thank you, was probably the only thing I hadn't tried!
0
 
Mark WillsTopic AdvisorCommented:
Wow, that was quick - didnt even know there was another post - well done OMC2000 :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.