Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Sunday, February 19, 2012

Adding datetime fields

Hi

I'm learning SQL, stuck on a problem, and would be very grateful if someone could point me in the right direction please.

I have a table that contains employee overtime data. The table contains the employee ID number, the work week ID, basic hours, and overtime hours worked.
What i want to do is SUM(OThrs) for a particular employee to get the total OT hours worked in a given workweek.

However, as I understand it the datetime datatype stores its value as a value measured from a base date of Dec-30-1899. As it wouldn't make sense to add the datetime fields due to this, is there any way around it?

The OThrs is brought in from a csv file through a DTS package and is in the format of.... eg 07:45, 13:20, 02:12, 08:10

So if those times above were all for the same employee in the same work week, it would total 31:27

I'd be grateful for some poiters on this problem.
Thanks & Regards
MartyT

If you did not specify any date part in the datetime value, then the date portion will default to 1900-01-01. Confirm that this is the case for those values. Assuming this condition, you can do the following:

select t.EmployeeId, t.WorkWeekId,
convert(varchar(5), dateadd(minute, sum(datediff(minute, '', t.Othrs)), ''), 114) as total_ot_hours
from tbl as t
group by t.EmployeeId, t.WorkWeekId

Note that the above query only has resolution less than 24 hrs. If you need more than that, then take the minute value directly and generate the hour/minutes part yourself.|||That's a big help. Thanks for your time - much appreciated

Thursday, February 9, 2012

Adding a table to a publication

In testing (learning?) I added a table to a database after a publication was
created. Then I went to modify that publication but the new table didn't
show up in the list of articles. But when I did this with a view it did show
up. Is there something about new tables that prevents them from showing up
in the wizard? What if I use sp_addarticle?
Bob
Bob,
there's a checkbox in the publication properties, articles tab which allows
you to see unpublished articles - please can you check to see if it is this
that is preventing you from seeing the new table.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Yeah, that was checked. But I've since deleted the publication. Thanks.
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:epbCqnMrFHA.1252@.TK2MSFTNGP09.phx.gbl...
> Bob,
> there's a checkbox in the publication properties, articles tab which
> allows you to see unpublished articles - please can you check to see if it
> is this that is preventing you from seeing the new table.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>