Stored procedures Again

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonia.sardana
    New Member
    • Jul 2006
    • 95

    Stored procedures Again

    I create a stored procedure as follows-
    CREATE PROCEDURE student1 @roll int, @name varchar
    AS
    SELECT @roll as roll, @name as name
    GO


    To execute it---
    EXEC student1 1,'A'
    Result comes

    Again
    EXEC student1 2 ,'B'
    Result comes

    In stored procedure name student1 , these two rows are inserted or not.....
    If inserted how can i view rows of Stored Procedure....
    Like in table we can view rows as--
    Select * from table
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by sonia.sardana
    I create a stored procedure as follows-
    CREATE PROCEDURE student1 @roll int, @name varchar
    AS
    SELECT @roll as roll, @name as name
    GO


    To execute it---
    EXEC student1 1,'A'
    Result comes

    Again
    EXEC student1 2 ,'B'
    Result comes

    In stored procedure name student1 , these two rows are inserted or not.....
    If inserted how can i view rows of Stored Procedure....
    Like in table we can view rows as--
    Select * from table

    No, those rows were not inserted.

    Generally speaking, stored procedure (SP) does not store rows inside it. Tables are the most common way to store rows. SP's are just a collection of commands, queries, t-sqls that you gather together so that when you call it, it will execute all those commands and queries sequentially.

    I found a good primer for you here

    -- CK

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      To continue what you have started here.
      You need a table to save the values into
      called perhaps tblStudents
      with fields Roll and Name with datatypes int and varchar(50)


      Now you can change youre stored proc to
      Code:
      CREATE PROCEDURE student1  @roll int, @name varchar(50)
      AS
      
      --Insert a new row into tblStudents
      INSERT INTO tblStudents
      SELECT @roll as roll, @name as name
      
      --Now return the contents of the student table to the caller
      SELECT roll,name
      FROM  tblStudents
      
      GO
      now you can execute it like you were and get the results you were expecting

      --Add the first record
      EXEC student1 1,'A'

      --now add the second record
      EXEC student1 2 ,'B'


      There you go, that should get you started and help you to follow the tutorial posted in the previous post

      Comment

      Working...