sql server - SQL Update not working in a stored procedure unless run manually -


the following snipit of stored procedure (a.k.a. sp) have set running on mssql(a.k.a. db). sp used take data db view , export results csv file via bcp. works no issues. last step update db table, db view grabbing data, current time stamp. now, here issue. when manually run stored procedure via ms sql server management studio, works planned. when same sp executed externally via software, bcp export works yet update table not work, i.e. no current time stamp entry in table. declarations, variable sets, set ansi_nulls on , set quoted_identifier on in place prior snipit.

suggestions?

curt

if exists (select * dticket formid = @formid)  begin     select @csvdata = 'select * dticket formid = '''+@formid+''''     select @bcpsql ='bcp "'+ @csvdata + '" queryout "'+ @filepath + @filename + '" -c -t"|" -u '+@user+' -p '+@pw+' -s '+ @server +' -d maindb'     exec master..xp_cmdshell @bcpsql     update "udticket" set exportdate = getdate()  formid = @formid , exportdate null  end 

have @ following article https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-transact-sql seem update happening before bcp done. capture return value xp_cmdshell example below

declare @rtn int  exec @rtn =exec master..xp_cmdshell @bcpsql if @rtn = 0 begin update "udticket" set exportdate = getdate()  formid = @formid , exportdate null  end  else ..... 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -