Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table named 'tblgrademaster' in sqlserver2000.I have five fields in it .they are given below.@gradeid bigint,@exam bigint,@limit1 float,@limit2 float,@grade varchar(50)Now I wrote stored procedure to insert thisinto table.ALTER PROCEDURE [dbo].[insertgrademaster](@gradeid bigint,(primary Key)@exam bigint,@limit1 float,@limit2 float,@grade varchar(50))ASinsert into tblgrademaster values (@gradeid,@exam,@limit1,@limit2,@grade)The insert operation is success.NOw i want a query like...If fields @gradeid,@exam,@limit1,@limit2,@grade exists in a row(in my table),it should update the row,if not exists it should insert.How will be the query(stored procedure)Plz help me by modifying my querythanks
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2009-08-31 : 02:42:02
[code]if exists(select * from table where grade=@gradeid and exam=@exam and ........) update table........else insert into .......[/code]MadhivananFailing to plan is Planning to fail
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-09-02 : 06:43:25
or:-
ALTER PROCEDURE [dbo].[insertgrademaster](@gradeid bigint,(primary Key)@exam bigint,@limit1 float,@limit2 float,@grade varchar(50))ASupdate tblgrademasterset exam=@exam,limit1=@limit1,limit2=@limit2,grade=@gradewhere gradeid=@gradeidIF @@ROWCOUNT=0BEGINinsert into tblgrademaster values (@gradeid,@exam,@limit1,@limit2,@grade)ENDGO