Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-01 : 08:28:06
|
| Marc writes "When I insert a record in table I put NOW into datetimefield.I also store value into date-variable varmutdatAfterwords I want to select record with query on this datetimefield with the value varmutdat.Error: the conversion of a char data type to a datetime datatype resulted in an out-of-range datetime value.code:recordset.open ,"select [date-column] from [tbl] WHERE ([date-column] = " & "'" & VARMUTDAT & "'" & ")",[connection],,,adcmdtextWhen I do not use the variable VARMUTDAT but the actual data (29-10-2004 10:12:04 then I do get the right record out of the query!I guess it is something about the variable type or conversion...Any help wouldt be much appreciated.Marcms sql server 2000/win2k/vb 6" |
|
|
Knarf180
Starting Member
42 Posts |
Posted - 2004-11-01 : 09:11:38
|
| Well VARMUTDAT looks to be your internal variable. Debug it and see what it actually contains. I'm sure your answer is in there, you may need to format it correctly so that MSSQL can read it. |
 |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-11-01 : 12:37:23
|
tryrecordset.open ,"select [date-column] from [tbl] WHERE [date-column] = '" & FORMAT(VARMUTDAT,"yyyy\/mm\/dd hh:ss") & "'",[connection],,,adcmdtext |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-01 : 13:45:23
|
| and, as always: this is why stored procedures were invented. Use a stored proc and pass a parameter.- Jeff |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2004-11-01 : 21:42:22
|
| recordset.open ,"select [date-column] from [tbl] WHERE ([date-column] = #" & VARMUTDAT & "#)",[connection],,,adcmdtextor better use datediff, where datediff(day,[date-column],getdate())=0getdate gives you NOW--------------------keeping it simple... |
 |
|
|
|
|
|
|
|