Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 1.28 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. T-SQL Function to get ASCII values of characters stored
  2. SET NOCOUNT ON
  3. -- Create the variables for the current character string position
  4. -- and for the character string.
  5. DECLARE @position int, @string char(15), @output char(1000), @output2 char(2000)
  6. -- Initialize the variables.
  7. SET @position = 1
  8. SET @output2 = 'Start:'
  9. SELECT @string = name from
  10. location where location_type = 4405 and owner_id = 362
  11. and location_id = 53183
  12. WHILE @position <= DATALENGTH(@string)
  13.  
  14.        BEGIN
  15.        SELECT @output = CAST(ASCII(SUBSTRING(@string, @position, 1)) AS CHAR)
  16.         + ' ' +      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
  17.         PRINT @output
  18.         --SET @output2 = @output2 + '=' + @output
  19.         SET @position = @position + 1
  20.        END
  21.         --PRINT @output2
  22.     SET NOCOUNT OFF
  23.     GO
  24.        
  25. DECLARE @string char(15),
  26. @output1 varchar(1000),
  27. @output2 varchar(1000)
  28.  
  29. SELECT @string = name
  30. from  location
  31. where location_type = 4405 and owner_id = 362
  32. and location_id = 53183
  33.  
  34. SET @output1 = ''
  35. SET @output2 = ''
  36.  
  37. select
  38.     @output1 = @output1 + SUBSTRING(@string, number, 1) + ', ',
  39.     @output2 = @output2 + cast(ASCII(SUBSTRING(@string, number, 1)) as varchar) + ', '
  40. from master..spt_values
  41. where type='p' and number between 1 and LEN(@string)
  42. order by number
  43.  
  44. PRINT @output1
  45. PRINT @output2