[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


SQL - Comma inside a string?

Posted on 2007-07-31
Medium Priority
Last Modified: 2010-03-19

declare @name as varchar(50)

set @name = 'somestring'

select @name:

How can I make @name return 'somestring' (with commas)?

Thank you.
Question by:Endelm
  • 4
  • 2
LVL 40

Accepted Solution

Richard Quadling earned 2000 total points
ID: 19599003
Do you mean quotes?

This is a comma ,
This is a single quote '
This is a double quote "
This is 2 single quotes ''
This is a backtick `

Try ...

DECLARE @name as varchar(50)
SET @name = '''something'''
SELECT @name

outputs ...


Author Comment

ID: 19599011
Thank you.
LVL 40

Expert Comment

by:Richard Quadling
ID: 19599015
And of course, I didn't show you properly.

Remove the underscores ( _ ) from this line....

SET @name = '_'_'_something_'_'_'

Basically, a string uses single quotes around the text.

To embed a single quote you put into the string 2 single quotes.

So, say you want to have a string with 2 single quotes in it, you would need ....

SET @name = '_'_'_'_'_'

That's 6 single quotes, 2 for the fact that it is a string and 2 for each quote you want in the string.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40

Expert Comment

by:Richard Quadling
ID: 19599017

Author Comment

ID: 19599018
Thank you. That was great! :)
LVL 40

Expert Comment

by:Richard Quadling
ID: 19599180

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question