Reputation: 43
I have a table set up with the following rows:
Id_numbers | Name
-------------------------------------------------------
00001 | Clara Sujadi
00002 | Raj Setamil
00003 | Oakley Suherman
I want to concat
a value inside variable.
Here is what I've tried:
DECLARE @query VARCHAR(MAX)
SET @query = 'SELECT CONCAT(Id_numbers, Name, "some-text") FROM table_name'
EXEC @query
this always gives me error:
Invalid column name 'some-text'.
How to create a query concat
inside a variable?
Upvotes: 1
Views: 37
Reputation: 1269613
The correct delimiter for a string in SQL uses single quotes. You can double them to include them in a string:
DECLARE @query VARCHAR(MAX);
SET @query = 'SELECT CONCAT(Id_numbers, Name, ''some-text'') FROM table_name'
EXEC @query
Upvotes: 1