Saturday, January 19, 2013

ASCII VALUE IN SQL SERVER 2005


-- GRANT EXEC ON ASKY TO PUBLIC
CREATE PROC ASKY 
( 
@string VARCHAR(100) 
) 
AS BEGIN 
CREATE TABLE #ascii (ASCII int, LETTER varchar(1)) 
SET TEXTSIZE 0 
SET NOCOUNT ON 
-- Create the variables for the current character string position  
-- and for the character string. 
DECLARE @position int--, @string char(15) 
-- Initialize the variables. 
SET @position = 1 
--SET @string = 'ARKA GUPTA' 
WHILE @position <= DATALENGTH(@string) 
   BEGIN 
insert into #ascii 
   SELECT ASCII(SUBSTRING(@string, @position, 1)), 
      CHAR(ASCII(SUBSTRING(@string, @position, 1))) 
    SET @position = @position + 1 
   END 
update #ascii set LETTER = '%', ASCII = (select ascii('%')) where ascii = 32 --SPACE 
SET NOCOUNT OFF 
select * from #ascii 
END 
 
-- EXEC ASKY 'ARKA GUPTA'
-- DROP PROC ASKY

No comments:

Post a Comment