July 29, 2005 at 8:41 am
Using the following sample, how can I INSERT a column value that contains an apostraphe w/in the CountryName?
Countries CountryCode INT, CountryName nvarchar(256)
insert into Countries (CountryCode, CountryName)
values (5, 'Cote D'Ivoire')
(Notice the imbedded apostraphe in the value: D'Ivoire)
thx-
July 29, 2005 at 8:56 am
insert into Countries (CountryCode, CountryName)
values (5, 'Cote D''Ivoire')
Should do it.
Prasad Bhogadi
www.inforaise.com
July 29, 2005 at 8:57 am
SET NOCOUNT ON
DECLARE @Countries TABLE
(
CountryCode INT,
CountryName VARCHAR(100)
)
INSERT INTO @Countries VALUES (1, 'Country Name 1')
INSERT INTO @Countries VALUES (5, 'Cote D''Ivoire')
SELECT * FROM @Countries
Regards,
gova
July 29, 2005 at 8:57 am
replace the apostrophe with 2 single quotes to indicate that it is a literal value...
insert into Countries (CountryCode, CountryName)
values (5, 'Cote D''Ivoire')
**ASCII stupid question, get a stupid ANSI !!!**
July 29, 2005 at 9:20 am
Actually, to add to this...
Every time you have another level of nested single quotes, you have to double the number of them you use. I ran across this when I had to write a query similar to yours, but the entire text of the query was a string in my code. So the result was something like:
'INSERT INTO @Countries VALUES (5, ''Cote D''''Ivoire'')'
July 29, 2005 at 12:30 pm
you might want to try this
insert..... 'Cote D' + char(39) + 'Ivoire'
I find that easier than keeping track of how many single quotes I need to type.
Sara
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply