Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Error while creat the text file using SQL server 2005 Expand / Collapse
Author
Message
Posted Monday, July 18, 2011 10:45 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, December 22, 2014 12:13 PM
Points: 4,486, Visits: 455
Hi,

I am using the below code to create a text file from SQL server 2005.

DECLARE @vCmd VARCHAR(MAX)
DECLARE @vCLUEDATE VARCHAR(MAX)
DECLARE @vWorkfilename VARCHAR(MAX)

SET @vCLUEDATE = '000000001EFHRCF01FF 20110718205227VERI2011071820110718 2'
SET @vWorkfilename = 'F:\ClueUpload\CVGVER.20110718.0101.txt'

Select @vCmd = 'echo ' + @vCLUEDATE + '>' + @vWorkfilename

EXEC master..xp_cmdshell @vCmd

But it is creating the file without data, but it should create with one line of data.

Then i changed the @vCmd as below
Select @vCmd = 'echo ' + @vCLUEDATE + ' > ' + @vWorkfilename

then it is working. but it is adding one space to the end of line that is after 2 it is adding. but i don't want that space, so how can I do this.

Please help me on this...

Regards,
Sarath Babu Vellampalli


Kindest Regards,

Sarath Vellampalli
Post #1143540
Posted Monday, July 18, 2011 10:51 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, December 20, 2014 8:56 AM
Points: 6,748, Visits: 8,545
- can you elaborate on what you are actually trying to accomplish ?
- why are you using xp_cmdshell ?
- why aren't you using sqlcmd or bcp ? (maybe even just using a sqlagent job)
- is there a reason not to use SSIS ?


Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #1143543
Posted Monday, July 18, 2011 11:15 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, December 22, 2014 12:13 PM
Points: 4,486, Visits: 455
Hi ALZDBA,

I can't use SSIS because of client restriction.

by using my code it is adding one space to the end of the line, I have to elemenate that how can I do that please explain me. if there is any other way also.


Kindest Regards,

Sarath Vellampalli
Post #1143560
Posted Monday, July 18, 2011 11:56 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:04 PM
Points: 7,141, Visits: 12,768
To put it another way, are you sure you (or your client) chose the right tool for the job?

If not SSIS, then why not bcp, sqlcmd or even PowerShell via a SQL Agent job?


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1143603
Posted Monday, July 18, 2011 12:03 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Monday, December 22, 2014 12:13 PM
Points: 4,486, Visits: 455
Hi opc,

I am using this code in SP and we need to append the data to same text file with loop.

so please help me on this.


Kindest Regards,

Sarath Vellampalli
Post #1143611
Posted Monday, July 18, 2011 12:06 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, December 20, 2014 8:56 AM
Points: 6,748, Visits: 8,545
where will your file be located ? Does your sqlserver service account have the auth to read/write to that location ?


maybe have a look at the replies of this thread http://www.sqlservercentral.com/Forums/Topic1143504-392-1.aspx


Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #1143613
Posted Monday, July 18, 2011 2:30 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:04 PM
Points: 7,141, Visits: 12,768
Sarath Vellampalli (7/18/2011)
Hi opc,

I am using this code in SP and we need to append the data to same text file with loop.

so please help me on this.

I understand, but using ECHO with xp_CmdShell is pretty inflexible which is why myself and others have tried to guide you in a different direction. It may be possible, but maybe not. There are tons of examples on the web on how to use xp_CmdShell. Maybe try TYPE instead of ECHO? Good luck.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1143729
Posted Wednesday, August 20, 2014 1:56 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, December 18, 2014 7:29 AM
Points: 454, Visits: 646
Dear,

I know this very old post but ..

Solution is:-

Use

Select @vCmd = 'echo ' + @vCLUEDATE + CHAR(254) + '> ' + @vWorkfilename

and then excute below bat file

copy below code and make a bat file of that.

for /f "tokens=1,* delims=]" %%A in ('"type %1|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~2=%~3%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X> %1
) ELSE echo.
)

run above batch file using xp_cmdshell as

Select @vCmd = 'script.bat ' + @vWorkfilename + ' ' + CHAR(254)

EXEC xp_cmdshell @vCmd

I hope this will help.
Post #1605313
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse