Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to find ASCII characters in a table?


how to find ASCII characters in a table?

Author
Message
@SQLFRNDZ
@SQLFRNDZ
Mr or Mrs. 500
Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)

Group: General Forum Members
Points: 523 Visits: 1176
Hey Anuganti,

See if I understand you correctly the belwo would fit your requirement

CREATE FUNCTION dbo.GetAsciiValue
(
@str varchar(100)
)
RETURNS varchar(1000)
AS
BEGIN
DECLARE @res varchar(1000)

SELECT @res=COALESCE(@res,'')+CAST(ASCII(SUBSTRING(@str,number,1)) AS varchar(5))
FROM master..spt_values
WHERE type='p'
AND number BETWEEN 1 AND LEN(@str)

RETURN @res
END

then use it like

select name,number,dbo.GetAsciiValue(number) AS AsciiEqv
from yourtable


--SQLFRNDZ

Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45127 Visits: 39923
ranuganti (7/29/2011)
I have this type of ASCii characters in the column how do i find all in a single query other than alphanumarics.


Let's peel one potato at a time... :-)

Based on what you said and what emphasized in the quote above, are you asking to be able to find data that has anything other than A to Z, a to z, and 0 to 9 in it?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45127 Visits: 39923
Heh... also... why on Earth does it have to be a "single query"? You doing something for a contest or what? ;-)

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5689 Visits: 25280
If you need to know which characters have been found / or if found removed from the input string try this:

 DECLARE @Temp VARCHAR(30)
DECLARE @Found VARCHAR(30)
SET @Found =''
SET @Temp = 'A<>B=1,! \|-*()%$#@!'
SELECT @Temp AS 'Original input'
BEGIN
WHILE PATINDEX('%[^a-z^0-9]%', @Temp) > 0
BEGIN
SET @Found = @Found + (SELECT SUBSTRING(@Temp,PATINDEX('%[^a-z^0-9]%', @Temp),1))
SET @Temp = STUFF(@Temp, PATINDEX('%[^a-z^0-9]%', @Temp), 1, '')
END
SELECT @Found AS 'Found'
SELECT @Temp AS 'With characters removed'
END
Results:
Found
<>=,! \|-*()%$#@!
With characters removed
AB1



Note that the above will NOT find or remove the '^' character.

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
mkarthikeyyan 89837
mkarthikeyyan 89837
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 17
I have character or symbol in my column like "□". Please help me to find out the rows which are all having this("□") character.

My column value: Digital □ Packet Data

I have tried the following query :

select * from tbl_example where PATINDEX('%[□]%',field_name) > 0

I got results with "?" character. Please help me to find "□" character in the fields.

Thanks!!!
patrickmcginnis59
patrickmcginnis59
SSC-Addicted
SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)

Group: General Forum Members
Points: 431 Visits: 2333
mkarthikeyyan 89837 (11/1/2012)
I have character or symbol in my column like "□". Please help me to find out the rows which are all having this("□") character.

My column value: Digital □ Packet Data

I have tried the following query :

select * from tbl_example where PATINDEX('%[□]%',field_name) > 0

I got results with "?" character. Please help me to find "□" character in the fields.

Thanks!!!


I put:


SELECT '□' FIELD



into SQL and it returned "?". So it may be that your query actually works, but that SQL will display the box symbol as a question mark in query results.
mkarthikeyyan 89837
mkarthikeyyan 89837
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 17
Please help me to find unpredictable special characters like № , ffl in fields.

For example:

declare @tbl table(val nvarchar(100) null)

insert into @tbl
select 'ffl'
union all
select '№'
union all
select '©'


select * From @tbl


It returns "?" only. Please help me how to display these special characters?

Thanks!!!
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14959 Visits: 38977
mkarthikeyyan 89837 (11/1/2012)
Please help me to find unpredictable special characters like № , ffl in fields.

For example:
It returns "?" only. Please help me how to display these special characters?

Thanks!!!

because you implicitly converted nvarchar to varchar;

once converted to varchar's best guess, it cannot be undone,s o you get the boxy/question marks.
if you explicitly declare the strings with N'String' it works fine:


declare @tbl table(val nvarchar(100) null)

insert into @tbl
select N'ffl'
union all
select N'№'
union all
select N'©'

select * from @tbl



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

bleroy
bleroy
SSC-Enthusiastic
SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)SSC-Enthusiastic (172 reputation)

Group: General Forum Members
Points: 172 Visits: 739
As indicated in a previous reply, the '?' may be the right answer - remember that the SSMS query results panel is not a text editor, and it may be limited in displaying special characters.

Apart from the other suggestions, you could write a SP that would look at all the columns you are interested and go htrough each character (RBAR-max - i.e. row-by-row, column-by-column-character-by-character ;-)) and determine which ones you don't like.
You could also use regular expressions - which would be much better and faster.

I don't have access to SQLServer right now - working on Oracle today, in which case I would use something like:

-- match only alphanumeric characters (a-z, A-Z, and 0-9)
SELECT *
FROM regex_test
WHERE REGEXP_LIKE(regex_col, '[[:alnum:]]');



untested, but I think you can do something like
SELECT *
FROM yourtable
WHERE yourcolumn NOT LIKE '[a-z]|[A-Z]|[0-9]'



B
patrickmcginnis59
patrickmcginnis59
SSC-Addicted
SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)SSC-Addicted (431 reputation)

Group: General Forum Members
Points: 431 Visits: 2333
Here's a good page for some nice hints on dealing with unicode:

http://msdn.microsoft.com/en-us/library/ms180059.aspx
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