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

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -