Author |
Topic |
mole999
Starting Member
49 Posts |
Posted - 2011-01-11 : 08:10:37
|
Struggling to see the wood for the treesI'm Using GetUTCDate() - IsNull(jbhinv_rec.work_started + +jbhinv_rec.work_started_2, jbhinv_rec.booked_in_2 + +jbhinv_rec.booked_in) As Day,to get a date from the server time and then use either the combined start date with start time or the booked start date with start time, all that works perfectly for mewhat I can't manage to do is to take the resulting 06/05/1900 04:25:16 value and (A) present as Days, and then (B) repeating with the same query as [h]:mmits exporting to excel and i can convert it visually no problem, but it feeds a pivot table query which when drilled down produces the 1900 date systemI've looked at CAST, and CONVERT and DATEDIFF, but frankly totally lost at this time, and no longer can construct a good keyword searchgentle pointers much appreciatedMole |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-11 : 08:18:36
|
Maybe my brain is fried or something but I can't seem to understand your requirements. Can you write which columns you have, which datatype they are and what you expect the output to look like...??- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-11 : 08:37:03
|
quote: Originally posted by Lumbago Maybe my brain is fried or something but I can't seem to understand your requirements. Can you write which columns you have, which datatype they are and what you expect the output to look like...??- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
The relevant columns arejbhinv_rec.work_started Varchar(5)jbhinv_rec.work_started_2, Smalldatetimejbhinv_rec.booked_in_2 Varchar(5)jbhinv_rec.booked_in Smalldatetimenow if I have this rightGetUTCDate produces 11/01/2011 13:31:23andjbhinv_rec.booked_in_2 + +jbhinv_rec.booked_inwill produce a dd/mmm/yyyy hh:mm:ss valueI want to take the built value from the GetUTCDate which gives me a result like 06/01/1900 04:54:23That result, I want to convert to(A) whole days (output example 2)and also where necessary be able to convert to(B) total hours and minutes (output example 25:33) before it arrives on the spreadsheetMole |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-11 : 10:47:50
|
sorry didnt understand how you got 06/01/1900 04:54:23. can you elaborate?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-11 : 12:52:33
|
quote: Originally posted by visakh16 sorry didnt understand how you got 06/01/1900 04:54:23. can you elaborate?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Can't give you an exact value as I'm now at home, but if I take my derived value from the GetUTCDateGetUTCDate() - jbhinv_rec.work_started + +jbhinv_rec.work_started_2i.e. 11/1/2011 09:00:00 - 10/1/2011 08:00:00 I get a value that looks like 06/05/1900 04:25:16 as the result. If i format it in excel I get the hours or days as i need them, so I'm looking to apply the format before it gets to the spreadsheetMole |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-12 : 03:26:14
|
I feel kinda stupid here but I'm still not clear about the requirements. Can you provide insert statements to this table and also the *exact* format of the output you want? ->DECLARE @jbhinv_rec table ( work_started Varchar(5) work_started_2, Smalldatetime booked_in_2 Varchar(5) booked_in Smalldatetime ) - LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
Sachin.Nand
2937 Posts |
Posted - 2011-01-12 : 04:00:37
|
quote: The relevant columns arejbhinv_rec.work_started Varchar(5)jbhinv_rec.work_started_2, Smalldatetimejbhinv_rec.booked_in_2 Varchar(5)jbhinv_rec.booked_in Smalldatetime
Why some columns have varchar datatypes to save the datetime values ?PBUH |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 07:01:42
|
quote: Originally posted by Sachin.Nand
quote: The relevant columns arejbhinv_rec.work_started Varchar(5)jbhinv_rec.work_started_2, Smalldatetimejbhinv_rec.booked_in_2 Varchar(5)jbhinv_rec.booked_in Smalldatetime
Why some columns have varchar datatypes to save the datetime values ?PBUH
I have no idea, thats what SQLDrill shows exists when i look at the structure. Its as the structure has been put together, and what i have to work withMole |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 07:11:51
|
quote: Originally posted by Lumbago I feel kinda stupid here but I'm still not clear about the requirements. Can you provide insert statements to this table and also the *exact* format of the output you want? ->DECLARE @jbhinv_rec table ( work_started Varchar(5) work_started_2, Smalldatetime booked_in_2 Varchar(5) booked_in Smalldatetime ) - LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
I have READ ONLY access to the dataas for output if it can show total hours and minutes Like (67:34) also i want to be able show the 67 hours as 3 days, but obvious seperately, some records have been open for 87 thousand hours and I need to focus in on those so we can get them closed looking at Insert dosent seem to be what I want, I'm taking 4 columns,, if A and B are Empty then I will use C and D as in this part of the statementIsNull(jbhinv_rec.work_started + +jbhinv_rec.work_started_2,jbhinv_rec.booked_in_2 + +jbhinv_rec.booked_in) As Dayproducing ddmmmyyyy hh:mm:ssthat is a time in the past, so taking the current time and removing the previous from that I get the offset in hours and minutes or days since the job began, therefore at this moment in time I know how long we have been doing the job, so even if i could store that value, it would need to be updated constantly until the work is finishedMole |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-12 : 07:18:50
|
Well Mole my brain is fried too ... after looking all details .. However I think you are finding it difficult to move the data into Excel Sheet with the format as it looks in SQL? |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-12 : 07:27:47
|
I'm about to give up...is it really that hard to provide some SAMPLE data in a table format? You have read access to the database so it should be fairly simple to write some simple insert statements for some of the rows so we know what we are dealing with. Read this article -> http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-serverA good ways down it has a section called "DateTime Durations That Span Multiple Days" that will show you how do display the difference between two datetimes in days, hours, minutes and seconds. Unless you come up with some sample data this will be my last say on this matter!- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 07:46:15
|
Maybe I should state this differentlyI know that DateDiff(d, jbhinv_rec.work_started_2, GetUTCDate())Will give me Days between the current time and the midnight of the day, but i am missing the hours, hence combiningjbhinv_rec.work_started + +jbhinv_rec.work_started_2Can anyone tell me how to combine those two into a single date / time and name it so i can reuse that resultI still need to crack the IF one is set ISNULL then use the other, and the extra comma in DATEDIFF, is stopping that from workingI'm trying to avoid anything that is a write statement to the server as I don't have those priveldges hences doing this on the flyMole |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 08:03:50
|
quote: Originally posted by Lumbago I'm about to give up...is it really that hard to provide some SAMPLE data in a table format? You have read access to the database so it should be fairly simple to write some simple insert statements for some of the rows so we know what we are dealing with. Read this article -> http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-serverA good ways down it has a section called "DateTime Durations That Span Multiple Days" that will show you how do display the difference between two datetimes in days, hours, minutes and seconds. Unless you come up with some sample data this will be my last say on this matter!- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
Booked_In Booked_in_2 Work_started work_Started_212:00 20/05/2010 08:00 20/05/201012:00 30/04/2010 08:00 30/04/2010 11:47 07/01/201109:08 18/12/2010 09:08 18/12/201018:00 10/01/2011 17:30 10/01/201107:00 11/01/2011 17:00 10/01/2011 10:00 11/12/201012:18 12/01/2011 12:18 12/01/2011 12:21 12/01/201111:05 09/07/2010 11:00 09/07/201012:40 10/07/2010 07:00 14/10/2010 07:00 14/10/2010 08:00 14/10/201019:31 21/10/2010 19:31 21/10/201011:30 22/10/2010 11:30 22/10/2010some of th data has moved over, not all the booked are completed, and should workstartedI have no idea how to put a table in here I will go of and read that linkMole |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 08:44:45
|
quote: Originally posted by Lumbago I'm about to give up...is it really that hard to provide some SAMPLE data in a table format? You have read access to the database so it should be fairly simple to write some simple insert statements for some of the rows so we know what we are dealing with. Read this article -> http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-serverA good ways down it has a section called "DateTime Durations That Span Multiple Days" that will show you how do display the difference between two datetimes in days, hours, minutes and seconds. Unless you come up with some sample data this will be my last say on this matter!- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
I guess I'm not comprehending INSERT. To me that would place data in the SQL datatable on the Server, thereby changing the records ?? I can't find it meaning anything elseMole |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-12 : 09:05:16
|
What he wants is for you to provide insert statements so that he can run them (not you) to put data into test tables so that he can then test out queries for you.--Gail ShawSQL Server MVP |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 09:06:17
|
quote: Originally posted by GilaMonster What he wants is for you to provide insert statements so that he can run them (not you) to put data into test tables so that he can then test out queries for you.--Gail ShawSQL Server MVP
Ah that makes sense to me now, much obliged for the explanationMole |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 09:35:24
|
Is this right ?insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)08:00,20/05/2010,12:00,20/05/201008:00,30/04/2010,12:00,30/04/201011:47,07/01/2011,,09:08,18/12/2010,09:08,18/12/201017:30,10/01/2011,18:00,10/01/201117:00,10/01/2011,07:00,11/01/201110:00,11/12/2010,,12:18,12/01/2011,12:18,12/01/201112:21,12/01/2011,,11:00,09/07/2010,11:05,09/07/2010,,12:40,10/07/201007:00,14/10/2010,07:00,14/10/201008:00,14/10/2010,,19:31,21/10/2010,19:31,21/10/201011:30,22/10/2010,11:30,22/10/201012:00,30/12/2010,12:15,30/12/201010:00,30/12/2010,10:00,30/12/201007:00,11/01/2011,,14:36,11/01/2011,14:36,11/01/201106:00,12/01/2011,06:30,12/01/201112:30,23/12/2010,12:40,23/12/201013:52,14/12/2010,13:52,14/12/201015:15,09/01/2011,,20:45,11/01/2011,,07:00,12/01/2011,,07:00,12/01/2011,15:00,12/01/201114:00,31/12/2010,14:00,31/12/201007:51,12/01/2011,,07:00,12/01/2011,08:00,12/01/201108:00,12/01/2011,09:00,12/01/201116:20,17/11/2010,16:20,17/11/2010,,,15:00,09/12/2010,,08:45,12/01/2011,08:50,12/01/201108:53,12/01/2011,08:53,12/01/201108:30,12/01/2011,08:30,12/01/201110:00,12/01/2011,10:30,12/01/201110:30,12/01/2011,,08:30,12/01/2011,08:30,12/01/201112:00,06/01/2011,,07:00,09/12/2010,12:00,09/12/201008:00,11/01/2011,08:45,11/01/201108:30,11/01/2011,08:45,11/01/201113:36,12/01/2011,13:36,12/01/201113:44,12/01/2011,13:44,12/01/201112:00,12/01/2011,12:00,12/01/201116:45,06/01/2011,,08:00,10/01/2011,08:00,10/01/201113:30,30/11/2010,13:30,30/11/201015:00,08/01/2011,15:00,10/01/201108:00,10/01/2011,,14:00,07/01/2011,14:00,07/01/201108:37,06/01/2011,,,,08:30,07/08/201006:30,31/08/2010,10:00,31/08/201014:44,02/09/2010,,07:52,07/09/2010,07:52,07/09/201008:24,08/09/2010,08:24,08/09/201008:00,08/09/2010,08:09,08/09/201007:00,21/09/2010,,06:00,22/09/2010,06:00,22/09/201011:27,22/09/2010,11:28,22/09/201010:16,24/09/2010,10:17,24/09/201006:00,24/09/2010,06:00,24/09/201008:00,10/01/2011,,11:30,10/01/2011,,10:00,28/09/2010,10:00,28/09/201010:00,07/12/2010,11:00,07/12/201016:00,08/01/2011,16:30,08/01/201107:00,05/10/2010,07:30,05/10/201008:30,06/10/2010,08:30,06/10/201001:00,02/01/2011,,12:00,02/12/2010,12:00,08/12/201007:00,11/01/2011,07:00,11/01/201111:30,11/01/2011,11:30,11/01/201112:00,11/01/2011,,19:30,11/01/2011,11:58,12/01/201109:00,14/12/2010,09:00,14/12/201009:00,11/01/2011,11:00,11/01/2011,,10:13,09/12/201008:00,04/01/2011,,11:30,30/12/2010,11:45,30/12/201009:00,07/01/2011,,08:00,20/12/2010,11:30,20/12/201011:00,12/01/2011,11:00,12/01/2011Mole |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-12 : 10:02:32
|
No. Open up Books Online (SQL help) and look at the syntax of an insert.The first line is right, the second needs the keyword VALUES, some brackets and some quotes, and there can only be one set of values per insert statement.--Gail ShawSQL Server MVP |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 11:27:05
|
quote: Originally posted by GilaMonster No. Open up Books Online (SQL help) and look at the syntax of an insert.The first line is right, the second needs the keyword VALUES, some brackets and some quotes, and there can only be one set of values per insert statement.--Gail ShawSQL Server MVP
OK, I will do that, sorry about learning on the flyMole |
|
|
mole999
Starting Member
49 Posts |
Posted - 2011-01-12 : 11:43:24
|
insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:00","20/05/2010","12:00","20/05/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:00","30/04/2010","12:00","30/04/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("11:47","07/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("09:08","18/12/2010","09:08","18/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("17:30","10/01/2011","18:00","10/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("17:00","10/01/2011","07:00","11/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("10:00","11/12/2010","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("12:18","12/01/2011","12:18","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("12:21","12/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("11:00","09/07/2010","11:05","09/07/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("","","12:40","10/07/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","14/10/2010","07:00","14/10/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:00","14/10/2010","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("19:31","21/10/2010","19:31","21/10/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("11:30","22/10/2010","11:30","22/10/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("12:00","30/12/2010","12:15","30/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("10:00","30/12/2010","10:00","30/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","11/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("14:36","11/01/2011","14:36","11/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("06:00","12/01/2011","06:30","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("12:30","23/12/2010","12:40","23/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("13:52","14/12/2010","13:52","14/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("15:15","09/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("20:45","11/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","12/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","12/01/2011","15:00","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("14:00","31/12/2010","14:00","31/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:51","12/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","12/01/2011","08:00","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:00","12/01/2011","09:00","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("16:20","17/11/2010","16:20","17/11/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("","","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("15:00","09/12/2010","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:45","12/01/2011","08:50","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:53","12/01/2011","08:53","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:30","12/01/2011","08:30","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("10:00","12/01/2011","10:30","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("10:30","12/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:30","12/01/2011","08:30","12/01/2011")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("12:00","06/01/2011","","")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("07:00","09/12/2010","12:00","09/12/2010")insert into table_name (Booked_In, Booked_In_2,, Work_started, Work_started_2)VALUES ("08:00","11/01/2011","08:45","11/01/2011")Mole |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-12 : 13:54:46
|
Single quotes, not double quotes, like for all strings in SQL. Plus you have ,, in the insert. Is there a column name missing or did you just put an extra ,?Now, based on the sample data you've provided, what do you want as an output from this query?--Gail ShawSQL Server MVP |
|
|
Previous Page&nsp;
Next Page
|
|
|