Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Data containing ' Expand / Collapse
Author
Message
Posted Thursday, January 30, 2014 2:31 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 31, 2014 9:07 AM
Points: 4, 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!
Post #1536559
Posted Thursday, January 30, 2014 2:51 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Yesterday @ 4:55 PM
Points: 732, Visits: 6,167
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 '%''%'

Post #1536562
Posted Thursday, January 30, 2014 2:56 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 31, 2014 9:07 AM
Points: 4, Visits: 6
I am still getting the errors... something I'm doing wrong?
Post #1536563
Posted Thursday, January 30, 2014 3:04 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:50 AM
Points: 13,082, Visits: 12,547
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 Moden's 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)
Post #1536565
Posted Thursday, January 30, 2014 3:07 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Yesterday @ 4:55 PM
Points: 732, Visits: 6,167
I'm with Sean, we'll need some sample data and code to help you any further.
Post #1536566
Posted Thursday, January 30, 2014 3:19 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:50 AM
Points: 13,082, Visits: 12,547
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 Moden's 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)
Post #1536569
Posted Friday, January 31, 2014 6:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 31, 2014 9:07 AM
Points: 4, 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
Post #1536744
Posted Friday, January 31, 2014 7:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:50 AM
Points: 13,082, Visits: 12,547
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 Moden's 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)
Post #1536770
Posted Friday, January 31, 2014 8:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 31, 2014 9:07 AM
Points: 4, 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!
Post #1536794
Posted Friday, January 31, 2014 9:01 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:50 AM
Points: 13,082, Visits: 12,547
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 Moden's 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)
Post #1536824
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse