Solved

how do I convert tab to spaces in an sql field

Posted on 2012-03-14
2
331 Views
Last Modified: 2012-03-14
Hello:
I have the following function which I found in the internet and modified for my purposes, and I cannot make it to work.  I keep getting the same error-
"Invalid length parameter passed to the LEFT or SUBSTRING function."
I tried everything as shrinking the field size for the parameter and matching all variables to the same size, also changing the varchar for nvarchar, etc.
Please help!

ALTER FUNCTION [dbo].[ConvertTabsToSpaces] (@String varchar(7000))  
RETURNS varchar(7000) AS  
BEGIN
DECLARE
@start int,
@tempnote varchar(7000),
@temp char(1)


set @start=CHARINDEX(char(9), @String)
set @tempnote=substring(@String,1,(@start-1)) + ' '

While len(@String) > @start
begin
set @temp=substring(@String,@start,1)

IF @temp <> char(9)
begin
set @tempnote=@tempnote + @temp
end
else
begin
set @tempnote=@tempnote + ' '
end
SET @start=@start+1

END

RETURN(@tempnote)
end

thank you.
0
Comment
Question by:gloriagalvez
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 37721489
ConvertTabsToSpaces

declare @tab as nvarchar(1)
set @tab = char(9)

return replace(@tempnote, @tab, ' ')
0
 

Author Comment

by:gloriagalvez
ID: 37722478
Hello:
Thank you very much.  Since the field had different kind of characters, I had to use the following:

 Replace(Replace(Replace(Replace(Replace(Replace(Replace('|' + FTRN_HISTORY.EXTENDED_DESCRIPTION + '|', char(9), ''), char(35), ''), char(10), ''), char(11), ''), char(12), ''), char(44), ''), char(13), '') AS 'DESCRIPTION'

Thank you again.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now