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

Data transfer from sql query to .txt file error Expand / Collapse
Author
Message
Posted Friday, June 13, 2014 12:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:13 AM
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
Post #1580348
Posted Friday, June 13, 2014 1:58 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 11:46 PM
Points: 569, Visits: 903
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/
Post #1580381
Posted Friday, June 13, 2014 2:54 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:13 AM
Points: 4, Visits: 30
i too tried with queryout but it throws the same error,can you please help on this...
Post #1580397
Posted Friday, June 13, 2014 3:15 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 1:13 AM
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.
Post #1580411
Posted Friday, June 13, 2014 4:41 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 11:46 PM
Points: 569, Visits: 903

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/
Post #1580443
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse