Storing values in stored procedure

  • hi !

    i have the following SP

    ALTER Procedure [dbo].[Masters]

    @Id int,

    @Name varchar(100)

    As begin

    Declare @Masters as table (Id int primary key, Name varchar(100))

    Insert into @Masters Values (@Id, @Name)

    Select 'Record ' + CONVERT(varchar(8),@Id) + ' & ' + @Name + ' are inserted succesfully' + ' and the total count of Records are ' + CONVERT(varchar(10),COUNT(@Id))

    End

    I need to use it as a temp table without altering the database's original tables to store few records (not more than 20 lines).

    I am struck here, that when ever i am executing it, it jus shows up with only one record count.

    kindly give me a solution whenever i am executing a procedure it has to get in the values and stores the data in it itself and a way to view the records too..

    Thanks !

  • First off , you are using a table variable here not a temporary table.

    The table is being destroyed and recreated on each call so its not suprising your data is not there.

    You could swap to using a temporary table (#) , but as you are using RS , i dont think that there is a away to guarantee that the calls will all happen on the same connection. If that is the case then each connection be writing to a different temp table.

    Your best bet may be to create a new permanent table and write to that.



    Clear Sky SQL
    My Blog[/url]

  • Fine ThkQ !

    Left the idea to work on that further :O)

    got into another task.

Viewing 3 posts - 1 through 2 (of 2 total)

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