tsql - Stored Procedure Throwing Error But Updating Record -


i've got stored procedure update flag based on county code, url or combination of both. instance, county 03 might have these 2 records:

county_code = 03 webservice_type_id = 1 webservice_url = http://192.168.100.3/a 

and

county_code = 03 webservice_type_id = 2 webservice_url = http://192.168.100.3/b 

and if want use stored procedure enable/disable flag, should able run:

execute dbo.usp_webservice_change_status @enable = 1 @county_code = '03' @webserviceurl = http://192.168.100.3/b 

and update record matches both condidtions. seeing stored procedure updates records county throws raiserror statement in stored procedure.

for example, here current records:

enter image description here

and when run stored procedure:

enter image description here

i getting following:

enter image description here

but when @ records again, see have been updated: enter image description here

here code stored procedure. me understand wrong?

alter procedure [dbo].[usp_webservice_change_status]     @enable bit,     @county_code char(2) = null,     @webserviceurl varchar(4000) = null begin     set nocount on;      if @enable null         raiserror ('the value @enable should not null', 15, 1);      if ( @county_code null , @webserviceurl null )         raiserror ('the value @county_code , @webserviceurl cannot both null', 15, 1);      -- update county code     if (@county_code not null , @webserviceurl null )         update dbo.webservice_config         set [enable] = @enable,             comments = case                            when @enable = 1                                'enabled ' + suser_sname()                               else 'disabled ' + suser_sname()                        end         county_code = @county_code;      -- update webservice url     else if ( @county_code null , @webserviceurl not null )         update dbo.webservice_config         set [enable] = @enable,             comments = case                           when @enable = 1                               'enabled ' + suser_sname()                              else 'disabled ' + suser_sname()                        end             webservice_url = @webserviceurl;      -- update both county code , webservice url - if records match     else if (@county_code not null , @webserviceurl not null )         if (@@rowcount) < 1             raiserror('nothing updated due non matching records', 15, 1);          update dbo.webservice_config         set [enable] = @enable,             comments = case                           when @enable = 1                               'enabled ' + suser_sname()                              else 'disabled ' + suser_sname()                        end         (county_code = @county_code                 , webservice_url = @webserviceurl); end; 

in last else if checking both params not null, next line use

if (@@rowcount) < 1 

but don't see running query see if there matching record provided params.

i think want run like

if(select count(1) dbo.webservice_config) <> 1   raiseerror else   update 

just thought.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -