#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Help in adding variables to the sql code


    I'm building a salary calculator program using vb.net, access database, and sql to access the database.

    I need to copy all the rows from several tables into one table. So I thought about using the insert into select statement. The problem is, I need to take the value of one column, add it to a string variable from vb.net and insert it to the new table as one field.

    Further explanation, in one table, I have a field containing the number of the day in the month (1-31), I need to add it to a string variable from vb.net that contains the rest of the date (/MM/YYYY) and insert it into the other table.

    Is that thing possible?
    Thanks in advance and sorry for the long post.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,172
    Rep Power
    4274
    Originally Posted by Erez_Ko
    Is that thing possible?
    yup
    Code:
    INSERT
      INTO table2
         ( id
         , qty
         , dte )
    SELECT id
         , qty + 42 -- variable from vb
         , dy + '/10/2013' -- variable from vb
      FROM table1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    First of all, thanks for answering.
    Second, what is qty and dy? Example fields?
    And I didn't quite understood how to add the vb variable, I just type "--" before it?
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,172
    Rep Power
    4274
    Originally Posted by Erez_Ko
    Second, what is qty and dy? Example fields?
    example columns

    Originally Posted by Erez_Ko
    And I didn't quite understood how to add the vb variable, I just type "--" before it?
    no, the double dash indicates the start of a comment (actually, not sure if that's valid in msaccess)

    anyhow, your vb variables would be inserted into the query where i've got the 42 and the '/10/2013'

    sorry, i can't help you with the vb, i don't do vb, but i can move your thread to the vb forum if you want
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by r937
    example columns

    no, the double dash indicates the start of a comment (actually, not sure if that's valid in msaccess)

    anyhow, your vb variables would be inserted into the query where i've got the 42 and the '/10/2013'

    sorry, i can't help you with the vb, i don't do vb, but i can move your thread to the vb forum if you want
    Oh thanks, my question was how to insert the reference to the vb variable into the sql line..

IMN logo majestic logo threadwatch logo seochat tools logo