Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gmahi
Starting Member
9 Posts |
Posted - 2011-07-24 : 00:04:42
|
| HI,I have to pass location and sql query as parameters on to bcp command so that i can get my results for my work likeset @name =( query to get stored procedure name)set @filepath =(query to get file path) Set @command = 'bcp "Exec @name" queryout "@filepath " -c -t, -T -Sserver1'Exec master..xp_cmdshell @commandam getting errors by following the above scenario , please help me in getting the results by passing (@filepath and @query) parameters in bcp or is there any other way to achieve it. If please tell me |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-24 : 00:51:15
|
try like thisset @name =( query to get stored procedure name)set @filepath =(query to get file path) Set @command = 'bcp "Exec @name" queryout "' + @filepath +'" -c -t, -T -Sserver1'Exec master..xp_cmdshell @command ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
gmahi
Starting Member
9 Posts |
Posted - 2011-07-24 : 08:20:39
|
| Thnaks visakkh. Its working:) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-24 : 08:29:51
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
gmahi
Starting Member
9 Posts |
Posted - 2011-07-25 : 07:00:21
|
| hi am able to transfer the data to a excel file using above command but the cloumn fields are not exporting, is there any way to achieve it usin bcp command |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
gmahi
Starting Member
9 Posts |
Posted - 2011-07-25 : 11:52:56
|
| Yes please |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-25 : 12:06:12
|
| check the link it has a method------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|