need help to learn writing Stored Proc

  • Hi can someone help me to write a stored proc to add the 3 subjects and get their totals

  • create proc procname

    @subject1 int,

    @subject2 int,

    @subject3 int,

    @result int output

    as

    set @result = @subject1+@subject2+@subject3

    Is this want you want?

    I think this sproc will allow you to enter values for three subjects and then lets you add those values.

  • Here is a link to an article that was created to help new folks formulate posts that will get them the help they want. The information you've given so far is no where near enough to tell what you are trying to do. Please read the article and post your question with more detail so that we can help you.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • but when i excuted i got this below err msg,

    Msg 201, Level 16, State 4, Procedure procname, Line 0

    Procedure or function 'procname' expects parameter '@result', which was not supplied.

    @result should be displayed as o/p. why asking for a parameter to be supplied?

    please help as i new and struggling to learn sql server programming

  • A possible reason for error could me syntax error while trying to execute it.

    with this, it should run...

    declare @r int

    execute procname '1','2','3',@r output

    select @r

    thanks

  • You don't need the quotes in the execute command. The parameters are integers, not strings.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks much it worked and if i want to extend the pgm to calculate the percentage and give them the grade like A,B, C..

    Then how do i write?

    i appreciate your help

  • change this

    create proc procname

    @subject1 int,

    @subject2 int,

    @subject3 int,

    @result int output

    as

    set @result = @subject1+@subject2+@subject3

    to this

    create proc procname

    @subject1 int,

    @subject2 int,

    @subject3 int,

    as

    declare @result int

    set @result = @subject1+@subject2+@subject3

    it will only expect 3 parameters then

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Thanks for your inputs.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply