i***@gmail.com
2013-10-14 11:43:28 UTC
I am trying to create a txt file from sql server 2008 database which we have to send to the bank every night. I have tried rtrim, ltrim, replace but for some reason the data still contains empty spaces.
I also wrote the following sql function but this one also doesnt remove spaces.
CREATE FUNCTION [dbo].[fnRemoveAllSpaces]
(
@InputString VARCHAR(max)
)
RETURNS VARCHAR(max)
AS
BEGIN
--WHILE CHARINDEX(' ',@InputString) > 0 -- Checking for the spaces
SET @InputString =
LTRIM(RTRIM(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(
@InputString
,char(0),'')
,char(1),'')
,char(2),'')
,char(3),'')
,char(4),'')
,char(5),'')
,char(6),'')
,char(7),'')
,char(8),'')
,char(9),'')
,char(10),'')
,char(11),'')
,char(12),'')
,char(13),'')
,char(14),'')
,char(15),'')
,char(16),'')
,char(17),'')
,char(18),'')
,char(18),'')
,char(20),'')
,char(21),'')
,char(22),'')
,char(23),'')
,char(24),'')
,char(25),'')
,char(26),'')
,char(27),'')
,char(28),'')
,char(29),'')
,char(30),'')
,char(31),'')
,' ','')
))
RETURN @InputString
END
I also wrote the following sql function but this one also doesnt remove spaces.
CREATE FUNCTION [dbo].[fnRemoveAllSpaces]
(
@InputString VARCHAR(max)
)
RETURNS VARCHAR(max)
AS
BEGIN
--WHILE CHARINDEX(' ',@InputString) > 0 -- Checking for the spaces
SET @InputString =
LTRIM(RTRIM(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(
@InputString
,char(0),'')
,char(1),'')
,char(2),'')
,char(3),'')
,char(4),'')
,char(5),'')
,char(6),'')
,char(7),'')
,char(8),'')
,char(9),'')
,char(10),'')
,char(11),'')
,char(12),'')
,char(13),'')
,char(14),'')
,char(15),'')
,char(16),'')
,char(17),'')
,char(18),'')
,char(18),'')
,char(20),'')
,char(21),'')
,char(22),'')
,char(23),'')
,char(24),'')
,char(25),'')
,char(26),'')
,char(27),'')
,char(28),'')
,char(29),'')
,char(30),'')
,char(31),'')
,' ','')
))
RETURN @InputString
END