DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to imbed apostrophe inside a string?

The following Microsoft SQL Server T-SQL code samples demonstrate the usage of double apostrophes/single quotes and CHAR(39) to represent an apostrophe inside a string which is enclosed in single quotes. Apostrophe is the same as single quote.

-- Double up apostrophes/single quotes or use char(39) in concatenation

SELECT * FROM Northwind.dbo.Products

WHERE ProductName='Chef Anton''s Gumbo Mix'

------------

SELECT * FROM Northwind.dbo.Products

WHERE ProductName='Chef Anton'+CHAR(39)+'s Gumbo Mix'

------------

 

-- Place two apostrophes in the string to replace a single apostrophe

SELECT 'That''s the right amount on the John Deere tractor''s invoice.'

-- That's the right amount on the John Deere tractor's invoice.

GO

-- Using local string variable

DECLARE @string varchar(256) =

 'That''s the right amount on the John Deere tractor''s invoice.'

SELECT @string

-- That's the right amount on the John Deere tractor's invoice.

GO

 

-- Using char(39) - single quote - concatenation

DECLARE @string varchar(256) =

 'That'+CHAR(39)+'s the right amount on the John Deere tractor'+CHAR(39)+'s invoice.'

SELECT @string

-- That's the right amount on the John Deere tractor's invoice.

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE