Combine Columns

I have 3 numeric columns that I need to combine in one separated by a dash. The statement below adds the columns up instead of separating them by a dash.

SELECT FirstNum +'-'+ SecondNum +'-'+ ThirdNum AS TotalNum FROM DATA

Open in new window

Who is Participating?
Brian CroweConnect With a Mentor Database AdministratorCommented:
SELECT CAST(FirstNum AS VARCHAR(20)) + '-' + CAST(SecondNum AS VARCHAR(20)) + '-' + CAST(ThirdNum AS VARCHAR(20))

You may need to include ISNULL for each as adding null strings will get you a null result.
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.