Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error while creat the text file using SQL server 2005


Error while creat the text file using SQL server 2005

Author
Message
Sarath Vellampalli
Sarath Vellampalli
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4608 Visits: 464
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
ALZDBA
ALZDBA
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6966 Visits: 8838
- 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 w00t

- 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" :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Sarath Vellampalli
Sarath Vellampalli
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4608 Visits: 464
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
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8199 Visits: 14367
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
Sarath Vellampalli
Sarath Vellampalli
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4608 Visits: 464
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
ALZDBA
ALZDBA
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 6966 Visits: 8838
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 w00t

- 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" :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Orlando Colamatteo
Orlando Colamatteo
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8199 Visits: 14367
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
ashok84.kr
ashok84.kr
SSC-Addicted
SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)

Group: General Forum Members
Points: 458 Visits: 677
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search