views:

32

answers:

1

Dreadful title right? Thought I'd see if Stack overflow is quicker than me testing something while I get a thousand interruptions from other work :)

I'm updating an old VB net application and trying to refactor some of the logic as I go. The app looks for data from a single date across a few tables and writes that view to a file.

Writing the query in SQL I'd get the equivalent of

SELECT * FROM table
WHERE CAST(FLOOR(CAST(table.date AS float))AS datetime) = '15-Jul-2010'

Ideally I'd use

SELECT * FROM table WHERE date=@input

and add a date object as a parameter to a System.Data.SqlClient.SqlCommand instance

Are those two comparable? Will I get the results I expect?

+3  A: 

Yes the two are comparable, the SqlClient library will convert .net types to sql types. You would still have to truncate the time part in your sql query, so you could use something like:

SELECT * FROM table WHERE FLOOR(CAST(table.date AS float)) = FLOOR(CAST(@input AS float))

You don't have to convert back to datetime, but can just compare the floats.

Jappie
So stack overflow is quicker! :-)
Paul D'Ambra