Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In a database query that defines DATE values using ticks format and a WHERE clause that uses regular DateTime format, can query execution automatically convert to ticks format and return the correct results?

For example, as shown in the following sample code, when UTCTicks receives a regular date value as input, it's automatically converted to UTC ticks before the query runs:

where StartUTCTicks > 637212960000000000 and StartUTCTicks < 637345151990000000 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
269 views
Welcome To Ask or Share your Answers For Others

1 Answer

query automatically convert that to ticks and brings results from DB

Yes, you can make this happen automatically. The way you do it is by storing the value as a DateTime column in the first place!

Sql Server already stores datetime values in an efficient binary format. It does not store them as strings, unless you were foolish enough to choose a varchar type. Therefore, the only thing you gain by trying to use ticks in Sql Server instead of DateTime values is pain from losing easy access to the built-in DateTime functions and indexing, including automatically treating certain literals in your SQL code as DateTime values.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...