开发者

How does dotNet handle parameterised dates where programmatic date has no time but sql date has time

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 da开发者_StackOverflow社区te 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜