Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Insert a value into a sql statement

Results 1 to 8 of 8
Share This Thread →
  1. #1
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    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
    sqlconfused is offline Contributing User
    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    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 & "'"

  3. #3
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    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?

  4. #4
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    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

  5. #5
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    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

  6. #6
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    oh yes time must be included in ' (single quotes) it is SQL rule

  7. #7
    sqlconfused is offline Contributing User
    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    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.

  8. #8
    phoenixaz is offline Contributing User
    Join Date
    Feb 2008
    Posts
    790
    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.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

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

ASP Free Advertisers and Affiliates