Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Importing 00:00 into Table Expand / Collapse
Author
Message
Posted Monday, March 25, 2013 10:18 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:21 PM
Points: 79, Visits: 301
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!
Post #1435009
Posted Monday, March 25, 2013 10:27 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 8:05 AM
Points: 1,729, Visits: 491
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
Post #1435016
Posted Monday, March 25, 2013 10:32 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:59 PM
Points: 13,007, Visits: 12,426
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1435024
Posted Monday, March 25, 2013 10:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:21 PM
Points: 79, Visits: 301
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!
Post #1435037
Posted Monday, March 25, 2013 10:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:59 PM
Points: 13,007, Visits: 12,426
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1435041
Posted Monday, March 25, 2013 10:58 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:58 PM
Points: 20,705, Visits: 32,356
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?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1435052
Posted Monday, March 25, 2013 12:13 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:59 PM
Points: 13,007, Visits: 12,426
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1435084
Posted Monday, March 25, 2013 1:02 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 1:21 PM
Points: 79, Visits: 301
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.

Post #1435106
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse