SQL Server exec command works wrong -


i have stored procedure spresultflagupd gets 2 parameters @p_code_sazman , @p_code_marhale. stored procedure must update column true , false values

alter procedure [dbo].[spresultflagupd]      @p_code_sazman  nchar(6) = null,     @p_code_marhale nchar(6)=null     if exists(select * tblresult                code_marhale = @p_code_marhale                   , code_sazman = @p_code_sazman                  , confirmed = 1 , sendfile = 1 , makefileflag = 1)     begin         update tblresult          set makefileflag = 0         code_marhale = @p_code_marhale             , code_sazman = @p_code_sazman     end 

when run

exec spresultflagupd @p_code_marhale='000060', @p_code_sazman='000021' 

it not update table.

but when run update code sql query, works correctly.

when write code pure

   update tblresult      set makefileflag=0     code_marhale=@p_code_marhale  , code_sazman=@p_code_sazman 

it works correctly

the exists statement working. problem update. code being compiled before if being run. so, error occurs during compile stage.

you can fix using dynamic sql:

 if exists (select * tblresult code_marhale=@p_code_marhale  , code_sazman=@p_code_sazman , confirmed=1 , sendfile=1 , makefileflag=1) begin   exec sp_execute_sql n'update tblresult set makefileflag=0 code_marhale=@p_code_marhale  , code_sazman=@p_code_sazman'; end; 

try code own modifications


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -