sql server - SQL with input condition -


i have customer table-firstname,lastname,gender,salary. creating stored procedure 5 input parameters: @fn, @ln, @gndr, @slry , @type.

now, if @type=0 , @fn='sam' - then, should insert new record in table, if 'sam' existing in table. if @type=1 , @fn='sam' - then, should delete record table, if 'sam' existing in table. if @type=2 , @fn='sam' - then, should update record in table if 'sam' existing in table.

please me in creating query above condition.

please check solution . please create different case in sql server .

create procedure insertcustomer (      @fn varchar(30),      @ln varchar(30),      @gndr varchar(30),       @slry decimal(18,3) ,       @type int ) begin          if @type=0 , @fn='sam'          begin         insert customer(firstname,lastname,gender,salary)values(@fn,         @ln,@gndr,@slry,@type)            end           if @type=1 , @fn='sam'          begin            delete customer firstname= @fn                        end            if @type=2 , @fn='sam'          begin            update customer set              firstname=@fn,lastname=@ln,gender=@gndr,salary=@slry              firstname= @fn           end end   

it work . .


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

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

asp.net - Problems sending emails from forum -