Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have table called student in this table 7 fields are 1.std_id,2.std_name,3.maths,4.science,5.social,6.total,7.grade

i created store procedure for insert....

std_id,std_name,maths,science,social is in parameters.........

after entering these filed total=maths+science+social....

and grade should be checked where after that these two should be inserted
Posted

Check for feature of constraint feature. This is present in Oracle. Otherwise before insert one need to check for the logical condition.
 
Share this answer
 
CREATE PROCEDURE MyStoredProcedure AS
SET ROWCOUNT 10
SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC

Kishor Makwana
Software Engineer
Insight Softech
www.insightsoftech.com
 
Share this answer
 
Create PROCEDURE [dbo].[sp_Insert]

@vcstd_id AS INT
, @vcstd_name AS NVARCHAR(50)
, @vcmaths AS DECIMAL(18,0)
, @vcscience AS DECIMAL(18,0)
, @vcsocial AS DECIMAL(18,0)

, @iOutput AS INTEGER OUTPUT

AS
BEGIN

declare @vctotal AS DECIMAL(18,0)
declare @vcgrade AS NVARCHAR(50)

set @vctotal =@vcmaths + @vcscience + @vcsocial
if @vctotal< 150
BEGIN
SET @vcgrade = 'C'
END



INSERT INTO
student
(
std_id
, std_name
, maths
, science
, social
, total
, grade

)
VALUES
(


@vcstd_id
, @vcstd_name
, @vcmaths
, @vcscience
, @vcsocial
, @vctotal
, @vcgrade

)

SET @iOutput = 0 --New Record Successfully Insertted
END



try like this. write different formula to add grades.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900