Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

dymanic cloumns wiith some addtional logic

$
0
0

Hi All,

Hi All,

   I have a requirement where user want the output where column names would be dynamic .

as given structure of table .employee have different department  id with different date.

i want to output when the department changes for any employee it will show start date ,end date(next date for new department -1 ) and department id.

Table structure 													
emplid	date	        deptid	company	.	……	….							
1	1-Jan-13	test1	111										
1	3-Mar-13	Test2	111										
2	1-Jan-13	test1	111										
2	15/3/2013	Test3	111										
2	1-Apr-13	test6	111										
2	1-Jun-13	test5	111										

Output													
													
emplid	company	start date	end date	dept	start date	end date	dept2	start date	end date	dept	start date	end date	dept
1	111	1-Jan-13	28-Feb-13	test1	3-Mar-13		        Test2						
2	111	1-Jan-13	14-Mar-13	test1	15-Mar-13	31-Mar-13	test3	1-Apr-13	31-May-13	Test6	1-Jun-13		         test5

End date would be blank in case of last department.

Thanks and regards

Ritesh Handa


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>