July 7, 2009 at 2:57 pm
I want to write sql output of many queries to one file (that will be created by sql)
I use bcp but it so slow and have problems , do uhave any suggestion I searched alot without result any advice
best regards
July 7, 2009 at 8:49 pm
I've never experienced BCP being slow at anything. Usually, it's the associated query that's slow. Please post both the BCP command and the query being executed by BCP.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 7, 2009 at 10:09 pm
the other alternative is using SSIS packages.
Regards
Abhay Chaudhary
Sr.DBA (MCITP/MCTS :SQL Server 2005/2008 ,OCP 9i)
July 8, 2009 at 12:04 am
Jeff Moden (7/7/2009)
I've never experienced BCP being slow at anything. Usually, it's the associated query that's slow. Please post both the BCP command and the query being executed by BCP.
this is the query I use
SET @bcpCommand = 'bcp " select '''+ @expFile +'''" queryout "'
SET @bcpCommand = @bcpCommand + @exptionFile + '" -T -c'
EXEC master..xp_cmdshell @bcpCommand
it also give error
Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file
how can I fix that
the server is not the pc I work on it and I want to save the output on my pc
July 8, 2009 at 12:44 am
SET @bcpCommand = 'bcp " select '''+ @expFile +'''" queryout "'
SET @bcpCommand = @bcpCommand + @exptionFile + '" -T -c'
EXEC master..xp_cmdshell @bcpCommand
i don't think you can use '+' along with xp_cmdshell for multiple commands try using '&' instead.
what is @expfile and @exptionfile
Tanx 😀
July 8, 2009 at 6:29 am
Eswin (7/8/2009)
SET @bcpCommand = 'bcp " select '''+ @expFile +'''" queryout "'
SET @bcpCommand = @bcpCommand + @exptionFile + '" -T -c'
EXEC master..xp_cmdshell @bcpCommand
i don't think you can use '+' along with xp_cmdshell for multiple commands try using '&' instead.
what is @expfile and @exptionfile
He's not. The "+" is being used to build up the @bcpCommand through SQL concatenation of strings and string variables and will not appear in the final command.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 8, 2009 at 6:31 am
ali.m.habib (7/8/2009)
Jeff Moden (7/7/2009)
I've never experienced BCP being slow at anything. Usually, it's the associated query that's slow. Please post both the BCP command and the query being executed by BCP.this is the query I use
SET @bcpCommand = 'bcp " select '''+ @expFile +'''" queryout "'
SET @bcpCommand = @bcpCommand + @exptionFile + '" -T -c'
EXEC master..xp_cmdshell @bcpCommand
it also give error
Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file
how can I fix that
the server is not the pc I work on it and I want to save the output on my pc
Can you post the values for @expFile and @exptionFile as well, please. Also, in order for this to work, you will need to create a share on it your PC that the server can "see" and then the files must be listed as UNC's instead of drive:pathname's.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 8, 2009 at 6:44 am
If you run bcp via xp_cmdshell, it will be executing on the server and can write a file to your PC only if you have set up a writeable share and use a full URL path for the filename.
You can also run scripts in Management Studio in SQLCMD mode, and use the :OUT command in the script to save the results to a local file. You can also run SQLCMD in a command window on your PC and use the "-o filename" parameter (or simple output redirection) to save the results to a local file.
July 8, 2009 at 7:23 am
Jeff Moden (7/8/2009)
ali.m.habib (7/8/2009)
Jeff Moden (7/7/2009)
I've never experienced BCP being slow at anything. Usually, it's the associated query that's slow. Please post both the BCP command and the query being executed by BCP.this is the query I use
SET @bcpCommand = 'bcp " select '''+ @expFile +'''" queryout "'
SET @bcpCommand = @bcpCommand + @exptionFile + '" -T -c'
EXEC master..xp_cmdshell @bcpCommand
it also give error
Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file
how can I fix that
the server is not the pc I work on it and I want to save the output on my pc
Can you post the values for @expFile and @exptionFile as well, please. Also, in order for this to work, you will need to create a share on it your PC that the server can "see" and then the files must be listed as UNC's instead of drive:pathname's.
the @expFile variable carry string depend on select statement
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply