Saturday, March 3, 2007

Determine ASCII values of characters in a string

Determine ASCII values of characters in a string
-- script to determine ascii values of characters in data
-- adjust it to point at a table, not the test string!

set rowcount 1
declare @Cnt int
declare @charcount int
declare @title varchar(500)

select @Cnt = 1

declare @Characters table
(
rownum int IDENTITY (1, 1) Primary key NOT NULL ,
letter char(1),
val int
)


select @title = 'the quick brown fox, jumped over the lazy dog'
-- select @title = column from table where criteriacolumn = criteriavalue

select @charcount = len(@title)
print @title

while @Cnt <= @charcount
begin
insert into @Characters (letter,val)
select substring(@title,@cnt,1), ascii(substring(@title,@cnt,1))
print substring(@title,@cnt,1)
print ascii(substring(@title,@cnt,1))
Select @Cnt = @Cnt + 1
end
set rowcount 0

No comments: