|
 |
|
Dev Articles Community Forums
> Programming
> ASP Development
|
null dates with asp3.0 (pulling out hair)
Discuss null dates with asp3.0 (pulling out hair) in the ASP Development forum on Dev Articles. null dates with asp3.0 (pulling out hair) ASP Development forum discussing your ASP or Visual Basic problems, solutions and code posts. Active Server Pages help you create dynamic websites using powerful scripting technologies.
|
|
 |
|
|
|

Dev Articles Community Forums Sponsor:
|
|

May 10th, 2002, 10:26 AM
|
red house painter
|
|
Join Date: Apr 2002
Location: South east England
Posts: 46
Time spent in forums: < 1 sec
Reputation Power: 17
|
|
null dates with asp3.0 (pulling out hair)
I want a quick piece of script which will test a date for an empty string, in which case post NULL but if there is a date, post the date which is within a variable.
it does one of the two, i.e if the date contains a date, i use formatdatetime,2 and its fine. the problem comes when i try to set a variable to null and post it in my insert statement, or on my editing page as an update statement.
how do i post a variable which contains null, to a date field in ms access?
matt
|

May 10th, 2002, 12:04 PM
|
Registered User
|
|
Join Date: May 2002
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
'dateVar=date variable, may be empty string
'dateField is the name of the column in the table
sql="insert into " & tblName & " (dateField) Values ("
sql=sql & iif(dateVar<>"", dateVar ,"null")
sql=sql & ")"
Is that what you mean?
|

May 11th, 2002, 03:36 AM
|
red house painter
|
|
Join Date: Apr 2002
Location: South east England
Posts: 46
Time spent in forums: < 1 sec
Reputation Power: 17
|
|
would that work then?
i didnt know you could put if statements in sql statements.
ill try it out though
thanks
|

May 11th, 2002, 08:33 AM
|
Registered User
|
|
Join Date: May 2002
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
no that iif is in the vbscript to build the sql statement
the sql statement is just a string so build it using standard vb string processing
actually iif may not be in vbscript - its in vb - you can either make your own iif or use an equivalent if then else. iif evaluates the first param, and if ithat's true it returns the second param else it return the third param
Last edited by bzzz : May 11th, 2002 at 08:35 AM.
|

May 11th, 2002, 12:48 PM
|
Registered User
|
|
Join Date: May 2002
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
iif() is in vb but not vbscript. here's from my vbscript library
function iif(condition, trueval,falseval)
if condition then
iif=trueval
else
iif=falseval
end if
end function
Last edited by bzzz : May 11th, 2002 at 12:52 PM.
|

May 19th, 2002, 07:54 AM
|
red house painter
|
|
Join Date: Apr 2002
Location: South east England
Posts: 46
Time spent in forums: < 1 sec
Reputation Power: 17
|
|
i managed to get around the problem, by doing this:
if strRevDate > "" then
strRevDate = "'" & FormatDateTime(strRevDate,2) & "'"
else
strRevDate = "null"
end if
and then in the update statement:
Review_date = " & strRevDate & "
so, if its a date, the single quotes get posted and if not, they dont. this seems to work a treat (i did a lot of testing  )
thanks for your advice, i just needed to use my brain a bit in the end.
matt
|
Developer Shed Advertisers and Affiliates
Thread Tools |
Search this Thread |
|
|
Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|