1

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?

1
  • Tag your question with the database you are using. Commented Jun 9, 2020 at 1:17

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.