SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data containing '


Data containing '

Author
Message
damcguire
damcguire
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 6
Is there any way to delete data that contains ' ?

example - desc field is "Bene's"

Trying to delete or update the field gives me these errors -

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 's'.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ')
Somehow the app is allowing the data to get in there... Thanks!
roryp 96873
roryp 96873
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 6611
If you're trying to include a single quotation mark in a string, you have to escape it with another single quote. So your code would look something like:


delete from mytable
where myvar like '%''%'


damcguire
damcguire
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 6
I am still getting the errors... something I'm doing wrong?
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64720 Visits: 17979
damcguire (1/30/2014)
I am still getting the errors... something I'm doing wrong?


Can you post the code you are trying to run?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
roryp 96873
roryp 96873
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1693 Visits: 6611
I'm with Sean, we'll need some sample data and code to help you any further.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64720 Visits: 17979
Not sure we need to go so far as full table definitions and sample data. I suspect this is far simpler. OP, please post the update/delete statement and we can probably help you in a matter of minutes.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
damcguire
damcguire
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 6
actual data in the field is Number of Bene's

among other things, this is the SQL I most recently tried

Delete from rcd_def_dtl
where rcd_prop_desc like '%''%'

errors returned

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 's'.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ')

Updating the field only would be okay, but ultimately we would like to delete the whole record.

Thanks
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64720 Visits: 17979
damcguire (1/31/2014)
actual data in the field is Number of Bene's

among other things, this is the SQL I most recently tried

Delete from rcd_def_dtl
where rcd_prop_desc like '%''%'

errors returned

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 's'.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string ')

Updating the field only would be okay, but ultimately we would like to delete the whole record.

Thanks


The code you posted will not return that syntax error. There must be something else you are doing.


create table #rcd_def_dtl
(
rcd_prop_desc varchar(30)
)

insert #rcd_def_dtl
select 'Number of Bene''s'

select * from #rcd_def_dtl
where rcd_prop_desc like '%''%'

delete from #rcd_def_dtl
where rcd_prop_desc like '%''%'

select * from #rcd_def_dtl

drop table #rcd_def_dtl



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
damcguire
damcguire
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 6
This syntax works fine to create the table, insert the data, and delete it... but will not work against my actual db field/data. Syntax I used and errors above were copied. Maybe there's somekind of constraint on the db that I'm not aware of. Fwiw, I had asked the software vendor's developers to delete similar data some time ago, and they were not able to. Thanks for trying to help!
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64720 Visits: 17979
damcguire (1/31/2014)
This syntax works fine to create the table, insert the data, and delete it... but will not work against my actual db field/data. Syntax I used and errors above were copied. Maybe there's somekind of constraint on the db that I'm not aware of. Fwiw, I had asked the software vendor's developers to delete similar data some time ago, and they were not able to. Thanks for trying to help!


So post the ddl to create your table. Since we don't know your datatypes we are guessing.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search