Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 5123

Preserve Leading Zeros in SQL export to TXT

$
0
0

I need to export accounting data from SQL to a series of TXT files, with a "ServiceCode" of 02. I cannot get the leading zero to stick.

Here is the section of the SQL stored procedure that pulls the serviceCode of “02.”

       IF @serviceCode ='02'

       BEGIN

           SELECT @total =COALESCE(SUM(Price),0), @itemCount = COALESCE(SUM(ItemCount),0)

           FROM #tblData

           WHERE CostCenter = @costCenterAND ServiceCodeIN(SELECTDISTINCT [ServiceCode]

               FROM [DsPcDb].[dbo].[Service_T]

               WHERE [Name]NOTLIKE'%color%'AND [Name]NOTLIKE'%scan%'AND [Name]NOTLIKE'%fax%'AND [ServiceCode] <=196623)

       END

...and here is some text from the "02" output .txt file, with the leading zero stripped out of the third column:

11/21/2014,00000-24057,2,1125

11/21/2014,00001-MKTG12,2,150

11/21/2014,40059-00395,2,62

11/21/2014,40059-00409,2,32

11/21/2014,40059-00428,2,12

11/21/2014,40059-00432,2,2

11/21/2014,40059-00434,2,218

This won't let the receiving database import the data. ("02" is a specific code.) Three other txt files from this procedure are imported properly.

Please help! Thanks!





Viewing all articles
Browse latest Browse all 5123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>