...

View Full Version : Add variable to Dateadd



terp_in_umcp
02-12-2007, 03:09 PM
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!

Spudhead
02-12-2007, 03:34 PM
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?

terp_in_umcp
02-12-2007, 03:40 PM
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!

terp_in_umcp
02-12-2007, 04:50 PM
Any help???

degsy
02-13-2007, 02:35 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum