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 12»»

Finding a quote in a string Expand / Collapse
Author
Message
Posted Wednesday, December 19, 2012 2:47 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, December 28, 2012 1:39 PM
Points: 141, Visits: 189
What can I use to find if a string contains a '? I know how to replace the quote with a blank but I don't know how to determine if the string contains a quote.

--If @dest_city contains a quote
select @dest_city = replace(@dest_city,'''',' ')
Post #1398681
Posted Wednesday, December 19, 2012 2:59 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 3:56 PM
Points: 1,324, Visits: 1,778
string_column LIKE '%''%'

or:

CHARINDEX('''', string_column) > 0


SQL DBA,SQL Server MVP('07, '08, '09)
One man with courage makes a majority. Andrew Jackson
Post #1398685
Posted Wednesday, December 19, 2012 3:05 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, December 28, 2012 1:39 PM
Points: 141, Visits: 189
Thank you Scott.
Post #1398686
Posted Wednesday, December 19, 2012 5:33 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:03 AM
Points: 2,345, Visits: 3,191
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0



No loops! No CURSORs! No RBAR! Hoo-uh!

INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1398719
Posted Thursday, December 20, 2012 2:06 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, May 20, 2013 12:37 AM
Points: 1,049, Visits: 1,439
dwain.c (12/19/2012)
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0


Single Quote is char(39) Dwain......if I am not wrong.


Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden
Post #1398862
Posted Thursday, December 20, 2012 4:22 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 9:39 AM
Points: 4,247, Visits: 9,500
Another way:

where len(Col) > len(replace(Col, '''', ''))


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1398901
Posted Thursday, December 20, 2012 10:02 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:03 AM
Points: 2,345, Visits: 3,191
vinu512 (12/20/2012)
dwain.c (12/19/2012)
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0


Single Quote is char(39) Dwain......if I am not wrong.


Looked like a single quote when I SELECTed it but then sometimes my eyes aren't so good.



No loops! No CURSORs! No RBAR! Hoo-uh!

INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1399181
Posted Thursday, December 20, 2012 10:19 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, May 20, 2013 12:37 AM
Points: 1,049, Visits: 1,439
dwain.c (12/20/2012)
vinu512 (12/20/2012)
dwain.c (12/19/2012)
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0


Single Quote is char(39) Dwain......if I am not wrong.


Looked like a single quote when I SELECTed it but then sometimes my eyes aren't so good.


Don't worry Dwain......I'm always there to help


Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden
Post #1399182
Posted Friday, December 21, 2012 4:11 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:16 AM
Points: 2,236, Visits: 6,486
dwain.c (12/20/2012)
vinu512 (12/20/2012)
dwain.c (12/19/2012)
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0


Single Quote is char(39) Dwain......if I am not wrong.


Looked like a single quote when I SELECTed it but then sometimes my eyes aren't so good.


I can't display CHAR(25) on any of my servers, so it must be foreign

SELECT N, CHAR(N) AS CharResult
FROM (SELECT TOP 255
ROW_NUMBER() OVER (ORDER BY(SELECT NULL))
FROM master.sys.all_columns sc1
CROSS JOIN master.sys.all_columns sc2
)a(N);

Or, narrowed down to find the single quote: -
SELECT N, CHAR(N) AS CharResult
FROM (SELECT TOP 255
ROW_NUMBER() OVER (ORDER BY(SELECT NULL))
FROM master.sys.all_columns sc1
CROSS JOIN master.sys.all_columns sc2
)a(N)
WHERE CHAR(N) = '''';

Yep, CHAR(39). I used it far more than I should due to dynamic SQL



Not a DBA, just trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


LinkedIn | Blog coming soon (for sufficiently large values of "soon" )!
Post #1399320
Posted Monday, December 24, 2012 12:52 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 6:03 AM
Points: 2,345, Visits: 3,191
vinu512 (12/20/2012)
dwain.c (12/20/2012)
vinu512 (12/20/2012)
dwain.c (12/19/2012)
Since quote is also CHAR(25), you can also do this:

CHARINDEX(CHAR(25), string_column) > 0


Single Quote is char(39) Dwain......if I am not wrong.


Looked like a single quote when I SELECTed it but then sometimes my eyes aren't so good.


Don't worry Dwain......I'm always there to help


The weird thing about this is that now when I SELECT CHAR(25) it doesn't look at all like a quote. So I'm not sure what I selected when I did it.

Must be too much holiday cheer.



No loops! No CURSORs! No RBAR! Hoo-uh!

INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1399832
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse