Saturday, 15 May 2010

sql - Forcing Stored Procedure to check before inserting data into table -



sql - Forcing Stored Procedure to check before inserting data into table -

i created stored procedure,

now want is, replace if similiar type of record exists within table,

here's sp,

use [dbname] go create procedure [dbo].[insertdd] ( @columna varchar(1000), @columnb varchar(1000), @currentdateandtime datetime ) insert tablename ( columna, columnb, currentdateandtime ) values ( @columna, @columnb, @currentdateandtime )

now if table has column b value (regardless of difference in letters e.g. capital or lower case) update currentdateandtime value.

if not add together 3 of values.

do update, , if didn't find record update, insert:

update tablename set currentdateandtime = @currentdateandtime columnb = @columnb if (@@rowcount = 0) begin insert tablename ( columna, columnb, currentdateandtime ) values ( @columna, @columnb, @currentdateandtime ) end

sql sql-server-2005

No comments:

Post a Comment