Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 insert problem

Author  Topic 

Sep410
Posting Yak Master

117 Posts

Posted - 2008-08-20 : 18:26:10
Hi,
Here is my problem:
INSERT INTO [CFS].[dbo].[tbl_Comment]
([CaseID]
,[Comment]
,[ComDate]
,[AutoComment])
VALUES
('46',' FM Group: Changed to Nobody's Perfect *** ','8/20/2008 4:11:00 PM','True')

Comment fields originaly contains "'" What can I do?Comment will change evry time by user.
Please help me.

Sep

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-20 : 18:41:26
Double up the single quote.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sep410
Posting Yak Master

117 Posts

Posted - 2008-08-20 : 18:48:22
the problem is I don't know when the comment has ' in it.

Sep
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-20 : 18:49:04
Are you doing this through application code or via a script of some sort?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-20 : 18:57:11
If the answer to my above question is application code, then you need to handle this in there by using parameterized queries rather. You not only avoid this issue but also SQL injection.

Read this for more information:
http://it.toolbox.com/wiki/index.php/How_do_I_escape_single_quotes_in_SQL_queries%3F

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -