#1
  1. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    791
    Rep Power
    30

    Insert a value into a sql statement


    I want to ALSO insert into TABLE1 in the field name "signupdate" the signupdate which is "AZDATE".

    Code:
    sql= "insert into TABLE1 (CustomerID,productid)select customerid,productid from TABLE2,TABLE3 where TABLE2.customername = '"& customer &"' and TABLE2.customerid = '"& id &"' and TABLE3.productname = '"& productname&"' "
    I know I have to add it here....


    TABLE1 (CustomerID,productid,signupdate)

    ...but not sure how to add the value "azdate". AZDATE is properly formatted, just can't figure how to insert it.

    Code works ok but can't seem to add the date!

    Thanks for your help.
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    3
    Code:
    sql= "insert into TABLE1 (CustomerID,productid,signupdate) select customerid,productid from TABLE2,TABLE3 where TABLE2.customername = '"& customer &"' and TABLE2.customerid = '"& id &"' and TABLE3.productname = '"& productname&"' "
    would you not just add
    & productname&"', '" & AZDATE & "'"
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    791
    Rep Power
    30
    would you not just add
    & productname&"', '" & AZDATE & "'"
    I can't seem to get that to work by adding that. I am adding that to the end of the statement; would that be correct?
  6. #4
  7. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,608
    Rep Power
    278
    if your code
    sql= "insert into TABLE1 (CustomerID,productid)select customerid,productid from TABLE2,TABLE3 where TABLE2.customername = '"& customer &"' and TABLE2.customerid = '"& id &"' and TABLE3.productname = '"& productname&"' "
    works just

    sql= "insert into TABLE1 (CustomerID,productid, signupdate )select customerid,productid,"& AZDATE &" from TABLE2,TABLE3 where TABLE2.customername = '"& customer &"' and TABLE2.customerid = '"& id &"' and TABLE3.productname = '"& productname&"' "
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
  8. #5
  9. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    791
    Rep Power
    30
    Of course, I see that now. Thanks for that!

    When I do this... "& AZDATE &" I get 1/1/1900, so I did this...

    '"& AZDATE &"'

    and it works fine. Why is that?

    Thanks
  10. #6
  11. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,608
    Rep Power
    278
    oh yes time must be included in ' (single quotes) it is SQL rule
  12. #7
  13. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    3
    For the record, the code box in my last reply had the proper SQL string if you combined it with the suggestion as well, which is why I didn't respond. I thought you'd notice it.

    sql= "insert into TABLE1 (CustomerID,productid,signupdate) select customerid,productid from TABLE2,TABLE3 where TABLE2.customername = '"& customer &"' and TABLE2.customerid = '"& id &"' and TABLE3.productname = '"& productname&"', '" & AZDATE & "'"

    But alas you have it working now.
  14. #8
  15. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    791
    Rep Power
    30
    I did add that just as you last posted and it didn't work. I get this error message...

    [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','.

    When I added it per gk53, it doesn't error out and it inserts the date correctly.

    Thanks for your time, I do appreciate it very much and yes, alas it's now working.

Similar Threads

  1. SQL Insert Statement Won't Insert
    By Delo in forum ASP Development
    Replies: 2
    Last Post: January 7th, 2011, 06:22 PM
  2. Insert statement
    By Full Moon in forum ASP Development
    Replies: 3
    Last Post: May 17th, 2007, 06:19 AM
  3. Insert Statement
    By elenton in forum ASP Development
    Replies: 5
    Last Post: May 15th, 2007, 11:38 AM
  4. Replies: 7
    Last Post: March 21st, 2005, 10:58 AM
  5. Insert Statement
    By dcampos in forum ASP Development
    Replies: 4
    Last Post: October 22nd, 2004, 08:17 PM

IMN logo majestic logo threadwatch logo seochat tools logo