Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate a column value with single quotes in sql?

Tags:

sql

sql-server

How to concatenate a column value with single quotes and a comma in sql?

select tpaa_id  from dbo.Sheet
where tpaa_id is not null

At present query returns, value as ..

ABC123
ABC456

We have around 1000 records.

I expect to return as

'ABC123',
'ABC456',
like image 445
goofyui Avatar asked Jul 23 '15 13:07

goofyui


People also ask

How do I concatenate a single quote in SQL?

ANSI SQL has || as concatenation operator, while some products have a concat() function. Simply: 'My name' || '''' . I.e. double the single quote inside a string literal.

How do you concatenate a single quote?

To concatenate a quote mark in a calculation formula, put \" between quotations. In essence, the FirstName field is concatenated with a space, the double-quote character, the Nickname, the double-quote character, a space and the LastName.

How do I display single quotes in SQL?

Example SQL with Quotes. So here I have an example where I've declared some text, and I'm setting the text equal to my parent's car is broken. And here you can see I have a possessive “s”, with a single quote. DECLARE @text as NVARCHAR(400) SET @text = 'My Parent's car is broken.


1 Answers

Use this construction

SELECT CONCAT(CHAR(39), MyString ,CHAR(39)) FROM Table

return '<MyString>'
like image 91
Jiri Avatar answered Sep 25 '22 01:09

Jiri