Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Help please

Author  Topic 

Indsqlbeginner
Starting Member

21 Posts

Posted - 2014-03-31 : 04:33:38
Dear Team

i'm in need of your help guys.please help me out.

1.tblEmployee


Empid EmpFirstName
1 John
2 David
3 Peter



2. tblEmployeeProjectAllocationDetails


PrjCode PrjType EmpId FromDate ToDate
RFE Bench 1 2014-04-21 00:00:00 2014-04-28 00:00:00
LFG Leave 1 2014-02-21 00:00:00 2014-03-05 00:00:00
ABC Production 1 2014-01-01 00:00:00 2014-02-20 00:00:00
XYZ Support 2 2014-04-01 00:00:00 2014-05-31 00:00:00
FGH Production 2 2014-03-01 00:00:00 2014-03-31 00:00:00
TYH Leave 2 2014-02-28 00:00:00 2014-02-28 00:00:00
JYR Leave 2 2014-02-27 00:00:00 2014-02-27 00:00:00
BHR Bench 2 2014-02-21 00:00:00 2014-02-26 00:00:00
HYZ Support 2 2014-01-18 00:00:00 2014-02-20 00:00:00
RIO Bench 2 2013-12-19 00:00:00 2013-02-19 00:00:00
ERO Production 2 2013-02-01 00:00:00 2013-02-18 00:00:00
EIU Leave 3 2014-03-01 00:00:00 2014-04-22 00:00:00
GRE Leave 3 2014-01-06 00:00:00 2014-02-28 00:00:00
WTG bench 3 2013-12-21 00:00:00 2014-01-05 00:00:00
RQO bench 3 2013-12-14 00:00:00 2013-12-20 00:00:00
ERL Leave 3 2013-01-15 00:00:00 2013-12-13 00:00:00
HOO bench 3 2013-01-01 00:00:00 2013-01-14 00:00:00




Output


Empid PrjCode PrjType FromDate ToDate
1 ABC Production 2014-01-01 00:00:00 2014-02-20 00:00:00
2 HYZ Support 2014-01-18 00:00:00 2014-02-20 00:00:00
3 GRE Leave 2014-01-06 00:00:00 2014-02-28 00:00:00


Kindly note the following
1. have to look for 2014-02-28 00:00:00 (Feb 28 ,2014 ) between fromdate and Todate in allocation table.
- we may get more then one record but have to consider the lastest one

2. Basially need to find the production projcode for an employee before he falls into bench or leave before 28th feb.

*Production Prjcode means prjcode not in Bench or Leave

Conditions:
3. (if the PrjType is Leave and DateDifference ( day, fromdate,todate) < 180) or (If the PrjType is Bench and DateDifference ( day,fromdate,todate) < 10) ,we need to go through his histoty to find out the production code before he falls into bench.( Please refer ex 1 and 2)

4. incase, if there are no prod code found, return them with the first project code itself. ( Refer sample ex ; 3)


Thanks in Advance

sqlsaga
Yak Posting Veteran

93 Posts

Posted - 2014-03-31 : 11:57:26
Can you please explain your logic more clearly. Don't get it so easily with what you have written here...

Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
Go to Top of Page

Indsqlbeginner
Starting Member

21 Posts

Posted - 2014-04-02 : 02:39:08

sorry for not clear earlier.. i have updated the logic now in my earlier post itself.. request you to refer the sample input and output with the condtion given.
Thanks
quote:
Originally posted by sqlsaga

Can you please explain your logic more clearly. Don't get it so easily with what you have written here...

Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Go to Top of Page
   

- Advertisement -