Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to store time (not date) in SQL and query from VFP
Message
From
28/02/2008 22:22:53
 
 
To
28/02/2008 20:19:37
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01297626
Message ID:
01297656
Views:
30
Thanks John, I'll give it a shot... :o)

>Tracy, if you can wait for MSSQL2008, there is a time field type. ;-)
>
>Assuming you need to move ahead now: if you're absolutely sure you don't need the date(!) then storing the time as a char field has advantages- not least that it allows blank values as per a VFP table, which a MSSQL date or datetime field does not.
>
>Assuming you use a char field: If the user is selecting from an array/drop-down then it's easy to populate the field, using 24hr time of course.
>
>You could include the : values as per your TIME() suggestion, or rely on chrtran(time(),[:],[]) or SUBSTR(TTOC(DATETIME(),1),9) if you're feeling concise. ;-)
>
>The SQL is easy:
>
>
lcTime=chrtran(time(),[:],[])
>lcMySQL=[select * from dbo.mytable where cTime<=?lctime]
>...
>...
>...
>
>Note that if you are allowing blank time values, the blanks will be pulled by the above SQL. If this matters you might *want* to use a NULL value so that blank entries aren't caught.
>
>FWIW the above parameterized query will be cached by SQL Server, giving performance advantages over concatenated SQL. It is also injection-proof. ;-)
>
>Finally, you might also consider using an integer field if you want to store the whole time value without wasting bytes, but the cost of conversions etc probably exceeds the cost of a few bytes per record. ;-)
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform