Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2014
    Posts
    4

    Red face Unanswered: Need help with query for distinct dates

    Hi

    I have a need to only find distinct dates in which a worker worked in the factory using TSQL
    Code:
    RowNumber	 workerstartDate  	workerenddate
    1		 2012-08-08 		2012-10-10 
    2		 2012-08-10 		2012-08-31 
    3		 2012-09-05 		2012-09-15 
    4		 2012-10-15 		2012-12-19 
    5		 2013-01-02 		2013-03-14 
    6		2013-03-15 		2013-05-23
    Basically, I am looking for the above to look like this
    Code:
    rownumber	workerstartDate  	workerenddate
    1		2012-08-08 		2012-10-10 
    4		2012-10-15 		2012-12-19 
    5		2013-01-02 		2013-03-14 
    6		2013-03-15 		2013-05-23
    Can you please help.

    Thanks,
    Hans
    Last edited by hansr; 09-04-14 at 11:38. Reason: Updated workerid column to rownumber to avoid confusion

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'm afraid your question, as it is currently written, is unclear.

    Your first dataset contains 6 unique workerids and your second dataset only contains 4. I'm afraid I can't see why workerid 2 & 3 have been removed.

    Can you try and elaborate, please?
    George
    Home | Blog

  3. #3
    Join Date
    Sep 2014
    Posts
    4
    Hi George,

    The 2 rows have been removed as their dates fell inside the first range of date in row 1 i..e. from 8-8-2012 to 10-10-2012

    Rownumber workerstartdate workerenddate
    2 2012-08-10 2012-08-31
    3 2012-09-05 2012-09-15

    My apologies ... you are right .. The workerid column is actually misleading and actually pertains to the same worker as a Row Number .. I will edit it shortly in my previous post

    Thanks once again
    Hans
    Last edited by hansr; 09-04-14 at 11:42. Reason: adding column numbers for a better understanding

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •