SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Sqlcmd not trimming trailing white spaces
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arbrahul
Starting Member

2 Posts

Posted - 04/28/2013 :  18:39:24  Show Profile  Reply with Quote
Hi all,

I have a sql agent job which basically runs a stored procedure using sqlcmd and saves the output to a csv file. The stored procedure selects some data and there is one column with a lot of trailing spaces. I have used -W switch with sqlcmd to trim the space. This was working fine with SQL 2008 R2.

We have recently installed 2012 and moved the sql job to the new instance. Now the issue is that the text output file generated by the sqlcmd within the sqlagent job has all the trailing white spaces. Its not getting removed. Could anyone tell me how to get rid of these spaces ? I have run the sqlcmd command from a windows command against the new sql 2012 db and it works fine. It does not work with sql agent. That's all :(

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/28/2013 :  19:11:36  Show Profile  Reply with Quote
Make sure that the empty spaces are not due to line feed, carriage return or some other non printable ASCII characters...
You can try LTRIM() RTRIM() functions.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 04/29/2013 :  00:40:36  Show Profile  Reply with Quote
does the stored procedure involve any html code?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

arbrahul
Starting Member

2 Posts

Posted - 04/29/2013 :  05:24:48  Show Profile  Reply with Quote
The stored procedure is a simple select with a few joins. Unfortunately I could not modify the SP as it has been supplied by a service provider.
Go to Top of Page

UnemployedInOz
Yak Posting Veteran

Australia
54 Posts

Posted - 04/30/2013 :  05:36:18  Show Profile  Reply with Quote
Thinking out the box....

Create a new stored procedure of your own
In the stored procedure create a temporary table.
Insert into the temp table and call the service provider stored procedure
Return the information after removing extra characters.
Change you SQLCMD to run your SP

Create Procedure MyProcedure
As
Create Table #MyTable (TheData varchar(max))

Insert Into #MYTable (TheData)
EXECUTIVE ServiceProviderSP;

SELECT RTRIM(TheDATA) FROM #MyTable
go
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000