Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2007, 11:26 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error Inserting string containing (') and (,)

I tried inserting the following string "China, People's Republic of" using an INSERT INTO similar to this one:

INSERT INTO Table1 VALUES ('1', 'Test', 'China, People's Republic of')

but the (') and (,) interfere with the statement and I get an error message.

Can anyone tell me what I should use to qualify the value "China, People's Republic of" to make the statement work.

Hope this makes sense

I can't seem to find any help on the subject

Thanks in Advance
 
Old May 2nd, 2007, 01:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How you can't find help on this is beyond me, I tried "apostrophe sql" as a google search and the first result had the answer: http://www.google.co.uk/search?hl=en&q=apostrophe+sql

--

Joe (Microsoft MVP - XML)
 
Old May 2nd, 2007, 01:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dom55,

'China, People's Republic of' - Wrong usage
'China, People''s Republic of' - Correct usage.

' - is used to enclose char/varchar/nvarchar/text/ntext/datetime values when used in sql statements. You should be taking care of negating the ' that appears within the values using another '.

Cheers

_________________________
- Vijay G
Strive for Perfection
 
Old May 2nd, 2007, 01:41 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

replace (') with ('')

 
Old May 3rd, 2007, 04:39 PM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the 3 replies. The solution you provided worked perfectly.

Thank you very much.

Domininc


 
Old May 9th, 2007, 04:57 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

another option

change
INSERT INTO Table1 VALUES ('1', 'Test', 'China, People's Republic of')
to
INSERT INTO Table1 VALUES ('1', 'Test', 'China, People''s Republic of')

but changing the people's with people''s it tells sql that it is data and not a field terminator.


 
Old June 1st, 2007, 03:31 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

The replace is done with two single quotes ('') and not one double quote (").






Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird error when inserting into Access!!! tryston02 ASP.NET 1.0 and 1.1 Basics 1 April 6th, 2005 07:30 AM
Error inserting NULL value from form saturdave ASP.NET 1.x and 2.0 Application Design 2 January 12th, 2005 12:47 PM
Problem in inserting 100KB string into oracle db MSUser Oracle 1 December 31st, 2004 05:55 AM
inserting values error - Please help gtmm9 Classic ASP Databases 1 October 6th, 2003 11:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.