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 |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-05-06 : 15:29:00
|
| HiWhy am I not able to use a table created via CTE with xp_cmdshell to dump it to a text file? cPRLDetails AS(SELECT 1,2,3 FROM [dbo].[VmyVIew] vsp )EXEC master..xp_cmdshell 'bcp "Select * FROM cPRLDetails ORDER BY PartExt05" queryout "p:\targetfile.txt" -c -T'I get the following errorError = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'cPRLDetails'.Thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-06 : 15:30:21
|
It's out of scope. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-06 : 15:31:16
|
| Your bcp command is running in the default database of your windows account, which is probably master.SELECT * FROM dbName.dbo.cPRLDetailsI haven't a clue if it'll work with a CTE though.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-05-06 : 17:12:49
|
| Ok it is working with CTE had to do the following to it in case anybody needs to try thiscPRLDetails AS(SELECT 1,2,3FROM [dbo].[VmyVIew] vsp) SELECT PartExt05, PartMat, PartD, PartL, PartW, PartQtyINTO PRLDetails FROM cPRLDetails EXEC master..xp_cmdshell 'bcp "SELECT * FROM [dbname].dbo.PRLDetails Order By PartExt05 DESC" queryout "\\domainname\ShareFolder\Export.txt" -T -c -S[SQLServerName]' BEGIN IF OBJECT_ID('PRLDetails') IS NOT NULL DROP TABLE dbo.PRLDetails ; END |
 |
|
|
|
|
|