I am using a T-SQL block to get the dump of ascii characters stored in a database column. I know this is accomplished easily in Oracle using the DUMP() function. I am not taht familiar with SQL Server sytax, but I am using something like this.
SET NOCOUNT ON
-- Create the variables for the current character string position
-- and for the character string.
DECLARE @position int, @string char(15), @output char(1000), @output2 char(2000)
-- Initialize the variables.
SET @position = 1
SET @output2 = 'Start:'
SELECT @string = name from
location where location_type = 4405 and owner_id = 362
and location_id = 53183
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT @output = CAST(ASCII(SUBSTRING(@string, @position, 1)) AS CHAR)
+ ' ' + CHAR(ASCII(SUBSTRING(@string, @position, 1)))
PRINT @output
--SET @output2 = @output2 + '=' + @output
SET @position = @position + 1
END
--PRINT @output2
SET NOCOUNT OFF
GO
For some reason if I uncomment the code that relates to @output2, it won't print @output2 correctly. The idea is to get all the ascii values returned as a single line instead of getting a line for each character. Am I doing something wrong?