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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 select record on datetime field through visual basic

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 varmutdat
Afterwords 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],,,adcmdtext

When 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.

Marc

ms 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.
Go to Top of Page

VIG
Yak Posting Veteran

86 Posts

Posted - 2004-11-01 : 12:37:23
try
recordset.open ,"select [date-column] from [tbl] WHERE [date-column] = '" & FORMAT(VARMUTDAT,"yyyy\/mm\/dd hh:ss")  & "'",[connection],,,adcmdtext
Go to Top of Page

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
Go to Top of Page

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],,,adcmdtext


or better use datediff, where datediff(day,[date-column],getdate())=0

getdate gives you NOW


--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -