SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data transfer from sql query to .txt file error


Data transfer from sql query to .txt file error

Author
Message
sekhar.kandregula
sekhar.kandregula
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 30
Hi ,

Im trying to move data from sql query to .txt file im getting 'An error occurred while processing the command line.' only folder file is creaing and .txt file is not generating .

Please help on this.

Below is the script used .



declare @result int
DECLARE @Command NVARCHAR(4000)
create table #temp1(case_id int,pol_no varchar(20))


insert into #temp1 select case_id,case_app_ref_num from app_case

DECLARE @RecLoc int
declare @MaxLoc int
declare @cmd VARCHAR(8000)

SELECT @RecLoc = MIN(case_id),
@MaxLoc = MAX(case_id)
FROM #temp1
EXEC xp_cmdshell 'MKDIR e:\Files\file5'

WHILE @RecLoc < @MaxLoc
BEGIN

set @cmd='bcp "SELECT * from #temp1 where case_id='+ QUOTENAME(@RecLoc, '''') +'" out e:\Files\file5\1.txt -c -t, -T -S'+ @@servername

EXEC xp_cmdshell @cmd

SELECT @RecLoc = MIN(case_id)
FROM #temp1
WHERE case_id > @RecLoc
END

drop table #temp1
rhythmk
rhythmk
SSC Eights!
SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)

Group: General Forum Members
Points: 908 Visits: 1078
sekhar.kandregula (6/13/2014)
Hi ,
set @cmd='bcp "SELECT * from #temp1 where case_id='+ QUOTENAME(@RecLoc, '''') +'" out e:\Files\file5\1.txt -c -t, -T -S'+ @@servername


Try below.
set @cmd='bcp "SELECT * from #temp1 where case_id='+ QUOTENAME(@RecLoc, '''') +'" queryout e:\Files\file5\1.txt   -c -t, -T -S'+ @@servername



--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
:-)
sekhar.kandregula
sekhar.kandregula
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 30
i too tried with queryout but it throws the same error,can you please help on this...
sekhar.kandregula
sekhar.kandregula
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 30
Even i tried with this below one ...i getting below error output

declare @sql varchar(8000)

SELECT @sql = ‘bcp “select * from MM_DEV_T_D2_P..app_case” queryout E:\files\files\1.txt -c -t’+’”|”‘+’ -T -S @@servername’

exec master..xp_cmdshell @sql

—–err msg output

SQLState = 08001, NativeError = 53
Error = [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [53].
SQLState = 08001, NativeError = 53
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti
ons.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Native Client]Login timeout expired
NULL

plz help on this.
rhythmk
rhythmk
SSC Eights!
SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)SSC Eights! (908 reputation)

Group: General Forum Members
Points: 908 Visits: 1078

SELECT @sql = ‘bcp “select * from MM_DEV_T_D2_P..app_case” queryout E:\files\files\1.txt -c -t’+’”|”‘+’ -T -S @@servername’


Try below.

SELECT @sql = 'bcp "select * from MM_DEV_T_D2_P..app_case" queryout E:\files\files\1.txt -T -c'



--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
:-)
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