SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting into a db, from multiple tables

    hello,
    I have an insert SP as below

    Code:
    insert into accounting (item, price, quantity, purchaseID, username)
    select item1, price1, quantity1 from Accounting where userID = @user
    however i would like to combine 2 or more table to insert into the accounting table above to augument for the purchaseID and username.

    e.g. something like this;
    Code:
    insert into dbo.accounting (item, price, quantity, purchaseID, username)
    select item1, price1, quantity1 from dbo.Accounting where userID = @user , dbo.users purchaseID, username INNER JOIN     dbo.Users ON dbo.accounting.username = dbo.Users.username
    how do i go about this correctly ?

    thanks
    Afrika

  2. #2
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    finally got it to work, so i would luv to share my code with anyone who needs it

    insert into dbo.accounting (item, price, quantity, purchaseID, username)
    select t1.item1, t1.price1, t1.quantity1, t2.purchaseID, t2.username
    from dbo.Accounting t1
    INNER JOIN dbo.Users t2 ON t1.username = t2.username
    where t1.userID = @user


Bookmarks

Posting Permissions

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