March 25, 2013 at 10:18 am
So I've created a query that adds times to get a certain calculation. The end result I would get a time of 09:26, which means 9 minutes and 26 seconds. I can easily use the query directly into the report, but I'm wanting to dump the results into a table for historical reasons.
However, I'm running into an issue. When I attempt to import the results into a table, the import wants to change my 09:26 to an actual date and time, which I dont want.
What data type should the column be in the table so I'm allowed to import the 09:26 as it is?
Thanks!
March 25, 2013 at 10:27 am
few ways i can think of, which maybe of help or not:
1. store all times against one specific date so it is a datetime but only ever one
2. break minutes and seconds into 2 columns of type int or Small int
3. store in a decimal so for 9:26 you'd store 0.00655093 this way could be prone to rounding errors though.
My preference would be #1
March 25, 2013 at 10:32 am
Since you are trying to record the amount of TIME something took why not use the TIME datatype?
declare @Time time = '09:26'
select @Time
Now you have stored only the amount of time and you can still query it very easily.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 10:42 am
Sean Lange (3/25/2013)
Since you are trying to record the amount of TIME something took why not use the TIME datatype?
declare @Time time = '09:26'
select @Time
Now you have stored only the amount of time and you can still query it very easily.
This worked. Thanks!
March 25, 2013 at 10:48 am
DarthBurrito (3/25/2013)
Sean Lange (3/25/2013)
Since you are trying to record the amount of TIME something took why not use the TIME datatype?
declare @Time time = '09:26'
select @Time
Now you have stored only the amount of time and you can still query it very easily.
This worked. Thanks!
You're welcome. Glad that worked for you.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 10:58 am
Sean Lange (3/25/2013)
DarthBurrito (3/25/2013)
Sean Lange (3/25/2013)
Since you are trying to record the amount of TIME something took why not use the TIME datatype?
declare @Time time = '09:26'
select @Time
Now you have stored only the amount of time and you can still query it very easily.
This worked. Thanks!
You're welcome. Glad that worked for you.
Will work until you hit 24 hours. Is this a problem?
March 25, 2013 at 12:13 pm
Good point Lynn!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 25, 2013 at 1:02 pm
The 24 hour wouldnt be an issue, but I did go a different route. Instead of using the 00:00 format, I went ahead and converted the result to seconds. Then in my report will converted the x number of seconds to 00:00 format. I did this because of business unit and agent groupings.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply