Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
hi guysi am writing the query results to txt file. works fine on my local system when deployed the same SP on server i get error output----------------------------------------------------------------------SQLState = HY000, NativeError = 0Error = [Microsoft][SQL Native Client]Unable to open BCP host data-fileNULLthe command used is bcp "select * from Server..Table1 ,queryout "D:\Data\test.txt" -w -T -x ========================================Project Manager who loves to code.===============Ask to your self before u ask someone
basically i was generating dynamic sql. and then execute it. it works fine for me.. i fiqure out the issue is it was writting the data to remote drive which it does not have permission. gave permission and issue resolved.i have a new questioni need to execute the bcp command if the qry return any rows.declare @TSQL varchar(max)declare @SQL varchar(max)declare @rowcnt intset @sql='select * from table1 where ' + conditionset @TSQL ="select @rowcnt =count(sysid) from ( + @sql + )exec(@TSql)if (@rowcnt>0 )begin exec(@sql)..do some thing..endalso how can i avoid dynamic SQL========================================Project Manager who loves to code.===============Ask to your self before u ask someone
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2009-02-10 : 04:21:07
Do you have a D: drive on your server?All paths run on server are relative to server position.E 12°55'05.63"N 56°04'39.26"
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts
Posted - 2009-02-10 : 05:16:28
You'll need to store the count in a variable,, something like