Using Single Quotes in SQL Queries

Posted: February 7, 2007 in SQL Server

Did you ever searched how to use a single quote inside SQL query? In this article I explain how to do.

( 1.) To display a quote in between of two field values.
SELECT FirstName + ”’ ‘ + LastName From tblStudent

The above will put a single quote and a space in between FirstName and LastName fields.

( 2.) To insert a record with a quote to a table.
INSERT INTO [tbl] (ColumnName) VALUES (‘I’+”’m ok.’)

The above will insert a record into tbl and will put the string of {I’m ok.} to the column ColumnName.

( 3.) To update a record will be possible as follows.
UPDATE [tbl] SET ColumnName=’I’+”’m ok.’

The above will update ColumnName values of all the records of tbl in to {I’m ok.}.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s