Apr 2, 2007 #1 micang Technical User Joined Aug 9, 2006 Messages 626 Location US SQL 2000\Query Analyser Hi All, Is there a way of finding non-alphanumeric ('-', '*' etc and a space ' ') characters in a varchar (20) string? The characters can be in any position in the string. Any help appreciated. Michael
SQL 2000\Query Analyser Hi All, Is there a way of finding non-alphanumeric ('-', '*' etc and a space ' ') characters in a varchar (20) string? The characters can be in any position in the string. Any help appreciated. Michael
Apr 2, 2007 #2 gmmastros Programmer Joined Feb 15, 2005 Messages 14,912 Location US You can find the first non alpha-numeric character in a string, like this... Code: [COLOR=blue]Declare[/color] @Temp [COLOR=blue]VarChar[/color](20) [COLOR=blue]Set[/color] @Temp = [COLOR=red]'19238asdkj#sokfjsd9f'[/color] [COLOR=blue]Select[/color] [COLOR=#FF00FF]PatIndex[/color]([COLOR=red]'%[^0-9A-Z]%'[/color], @Temp) -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom Upvote 0 Downvote
You can find the first non alpha-numeric character in a string, like this... Code: [COLOR=blue]Declare[/color] @Temp [COLOR=blue]VarChar[/color](20) [COLOR=blue]Set[/color] @Temp = [COLOR=red]'19238asdkj#sokfjsd9f'[/color] [COLOR=blue]Select[/color] [COLOR=#FF00FF]PatIndex[/color]([COLOR=red]'%[^0-9A-Z]%'[/color], @Temp) -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
Apr 2, 2007 Thread starter #3 micang Technical User Joined Aug 9, 2006 Messages 626 Location US Thanks George. Excuse my ignorance, but I have never used declare before. How would I apply this to a table and a specific column? Thanks in advance. Michael Upvote 0 Downvote
Thanks George. Excuse my ignorance, but I have never used declare before. How would I apply this to a table and a specific column? Thanks in advance. Michael
Apr 2, 2007 #4 gmmastros Programmer Joined Feb 15, 2005 Messages 14,912 Location US You don't I declared a variable, set some data, and then tested some code. To use a column in a table... Code: Select PatIndex('%[^0-9A-Z]%', [!]Column[/!]) From [!]Table[/!] -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom Upvote 0 Downvote
You don't I declared a variable, set some data, and then tested some code. To use a column in a table... Code: Select PatIndex('%[^0-9A-Z]%', [!]Column[/!]) From [!]Table[/!] -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
Apr 2, 2007 Thread starter #5 micang Technical User Joined Aug 9, 2006 Messages 626 Location US blush... Thanks George, I see it shows a 0 where they are all alpha-numeric otherwise the character position/number of the first non-alpha-numeric. This is a great help and start. Many thanks. Michael Upvote 0 Downvote
blush... Thanks George, I see it shows a 0 where they are all alpha-numeric otherwise the character position/number of the first non-alpha-numeric. This is a great help and start. Many thanks. Michael