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

Convert ASCII strings to the integer groups of numbers? Expand / Collapse
Author
Message
Posted Tuesday, October 26, 2010 4:06 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, October 28, 2010 3:13 PM
Points: 3, Visits: 12
Please help me, my ignorance of SQL and ASCII has lead me to lose temendous amount of time trying to do this task.

I have ascii characters in an existing table column that range from single characters to sequentially doubled and tripled characters in range from 0 - 255. My goal is to read each string from each record and convert each charter in that string to it's number equivalent, group the numbers for the string and update another column in the same table with the number. ASCII strings (shown here separated by commas) like. '"/, aA╢, a8σ, %┐,{ '}{

I found this in SQL Server (ASCII convertion) help topic: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/45c2044a-0593-4805-8bae-0fad4bde2e6b.htm
But I'm SQL stupid and don't know how to loop, convert, group the values then pass the result back to the table in integer form.

Below is what I've been trying to modify to accomplish this task and not getting anywhere.

SET TEXTSIZE 0

-- Create variables for the character string and for the current
-- position in the string.

DECLARE @position int, @string char(8), @myval int

-- Initialize the current position and the string variables.

SET @position = 1

--here I'm trying to load the @string with a select statement ASCII string column
SET @string = SELECT dbo.FCCFRE.LIC_ID
FROM dbo.FCCFRE

--I want to update this column with the numeric value after it resolves the ASCII string to an integer string.
--I know this code puts out each code separately, but I need to group the values.
FOR UPDATE OF FRE_ID
--need to loop through each record but not know how to do it

WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 1)),
CHAR(ASCII(SUBSTRING(@string, @position, 1)))
SET @position = @position + 1
END
GO
--Don't know how to pass the number to @Myval and update the FRE_ID column.

This forum is my last resort, if no one knows how to do this I will have to call Microsoft for help!
TIA


Post #1011185
Posted Tuesday, October 26, 2010 10:52 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:41 PM
Points: 5,367, Visits: 8,989
Cross-posted. Please post all responses here.

Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #1011259
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse