Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add variable to Dateadd

    Hi there...I am trying to add a variable to the month in the dateadd function but everytime i do it it just inserts a null into the db. What i am really trying to do is...for the first record, it should add 1 to the month. For the 2nd record it should add 2 to the month and so on it the eof is reached...

    Here's the code...

    x=1
    do while pdcrecs.eof<>true


    mysql="UPDATE pdc SET deposit=DATEADD(month,x,'"&First("deposit")&"') WHERE number='"& Request.Cookies("EFC")("Account")& "' and UID='"& pdcrecs("UID")&"'"
    con.Execute(mysql)

    x=x+1

    pdcrecs.movenext
    loop

    -------------------------------------------------------------------------

    The moment I change the x to 1 or some number, it works fine. I also tried putting x in quotes but that dint work...any clues???

    Thanks!
    Last edited by terp_in_umcp; 02-12-2007 at 04:12 PM.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    remove this line:
    con.Execute(mysql)

    and replace it with this one:
    response.write(mysql & vbCrLf)

    then post your page output.

    What database are you executing this against?

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Output

    Hey Spud...here's the output from View Source:

    UPDATE pdc SET deposit=DATEADD(month,i,'1/1/2009') WHERE number='57246' and UID='2213'
    UPDATE pdc SET deposit=DATEADD(month,i,'1/1/2009') WHERE number='57246' and UID='2214'

    Here's the output on the page:

    UPDATE pdc SET deposit=DATEADD(month,i,'1/1/2009') WHERE number='57246' and UID='2213' UPDATE pdc SET deposit=DATEADD(month,i,'1/1/2009') WHERE number='57246' and UID='2214'

    The database is Sql server 2000. And right now it inserted a null into the deposit column for both rows...

    Thanks!
    Last edited by terp_in_umcp; 02-12-2007 at 04:44 PM.

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any help???

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are sending x as a string. You need to breakout of the string so you are submitting the variable.

    ASP VBScript also has a DateAdd function so I would breakout of the string and have the full function performed in ASP.


  •  

    Posting Permissions

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