Results 1 to 2 of 2

Thread: Help

  1. #1
    John Guest

    Help


    I am trying to insert results set into table after exec SP_spaceused. But the problem I am having is that, SP_Spaceused return two results set. So, My question is how do I insert two results into one table.

    I am able to insert results set if I exec SP_Spaceused 'customer'(by specifing the parameter).

    Thank You,
    john


  2. #2
    Raymond Wooley Guest

    Help (reply)

    -- Your db name goes here
    USE Customers

    -- Declare a cursor and then say that the cursor is going to consist of a select statement that selects these (dic, FName, etc.)
    -- from this (customer) table
    DECLARE tablecursor CURSOR FOR select cid, FName, MName, LastName from customer -- declare a cursor to hold the selected columns

    -- open the cursor
    OPEN tablecursor


    -- Now declare your variables to hold the values that are about to be fetched (this is kind of like playing that game Mancala)
    DECLARE @CID nvarchar (100)
    DECLARE @FName nvarchar(100)
    DECLARE @MName nvarchar(100)
    DECLARE @LastName nvarchar(100)
    DECLARE @FullName nvarchar(500)

    -- Next fetch the fields specified in the select atatched to the declared cursor above
    -- This is going to get the field cid and put it in @cid and then get fname and put it in @FName and so on...
    FETCH NEXT FROM tablecursor into @CID, @FName, @MName, @LastName

    -- Now it checks to see if there are more fields (are we at the end of the record? so to speak)
    -- if yes lets go do something with this info we have, if not find another field
    WHILE @@FETCH_STATUS = 0
    BEGIN

    -- Lets make @fullname = the values we just stuck in these three variables (containers)
    -- Were basically saying make the value for @fullname equal to the other three but put a space in between them.
    SET @FullName = @FName+''+@MName+''+@LastName

    -- Now lets insert the @full name (Mary + M + Jones) into a field on another table
    insert into FullNames (fullname) values (@FullName)

    -- Lets print it out to make sure things are happening right
    print @FullName

    --Get me the next row
    FETCH NEXT FROM tablecursor into @CID, @FName, @MName, @LastName -- get next recordset
    END
    -- This is executed as long as the previous fetch succeeds.
    CLOSE tablecursor
    DEALLOCATE tablecursor
    go


    ------------
    John at 1/18/01 2:03:37 PM


    I am trying to insert results set into table after exec SP_spaceused. But the problem I am having is that, SP_Spaceused return two results set. So, My question is how do I insert two results into one table.

    I am able to insert results set if I exec SP_Spaceused 'customer'(by specifing the parameter).

    Thank You,
    john


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •