question

Rio avatar image
Rio asked

How to combine string data with table column for SQL Query

Would it be possible to combine string data with table column in SQL Server Query. For example: DB name = soundsDB DB table = soundtype inside soundtype table: type, que Problems: Is it possible to combine 'Sing' and que using below query: case when type='1' then 'Sing- ' else 'Silence - ' End as DESCRIPTIONS Please advise. Thank you.
sql server
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered
Yes, you can do that. It would look something like this: SELECT CASE WHEN type = '1' THEN 'Sing-' + que ELSE 'Silence-' + que END AS Descriptions FROM dbo.SoundType; NOTE: This example is assuming that the [que] column is a string data type. If it's not, you'll have to CAST/CONVERT it to be a string for the concatenation to work correctly. Hope that helps!
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rio avatar image Rio commented ·
Thanks so much JohnM. it works
0 Likes 0 ·
JohnM avatar image JohnM commented ·
@Rio You are very welcome. If that solved your issue, please make sure to mark it as the answer so that others know the question was resolved. Thanks!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.