locked
how to perform this statement? RRS feed

  • Question

  • I am using this SQL in a stored procedure:

    INSERT INTO staff_address (staff_number, block_number, block_name) VALUES(@staff_number, @block_number, @block_name)

     

    and I want to update the value @block_number from blocks database with:

     

    SELECT * FROM blocks WHERE block_number = given_block_number

     

     

    Wednesday, October 11, 2006 8:42 PM

Answers

  • It sounds like you are looking for this:

    INSERT INTO staff_address (staff_number, block_number, block_name)
        SELECT @staff_number, block_number, block_name FROM blocks WHERE block_number=@block_num

    Friday, October 13, 2006 2:22 PM

All replies

    1. in the staff_database I have the block_number and block_name..
    2. the user will enter the block number
    3. the stored procedure should check the block name from the blocks_database.
    4. then the stored procedure will save the block_number (from the user's input) and the block_name (from the select result) in the staff_database
    Wednesday, October 11, 2006 9:18 PM
  • It sounds like you are looking for this:

    INSERT INTO staff_address (staff_number, block_number, block_name)
        SELECT @staff_number, block_number, block_name FROM blocks WHERE block_number=@block_num

    Friday, October 13, 2006 2:22 PM