Tuesday, February 8, 2011

Get Team Members of A Supervisor

/*


      Suppose you have table Employees as shown below


      EmployeeID  FirstName   LastName    ReportsTo


      1           Nancy       Davolio     2


      2           Andrew      Fuller      NULL


      3           Janet       Leverling   2


      4           Margaret    Peacock     2


      5           Steven      Buchanan    2


      6           Michael     Suyama      5


      7           Robert      King        5


      8           Laura       Callahan    2


      9           Anne        Dodsworth   5


      and you want to find employes to whom Steven Buchanan supervise


      you can use below query to retrieve the required list


*/


 


--Get Team Members of A Supervisor


 


Declare @EmployeeID Int


Set @EmployeeID = 5


 


;WITH GetEmployee(EmployeeId,EmpName)


      AS (


      Select EmployeeId,FirstName + ' ' + LastName as  EmpName


      From Employees  E


      Where EmployeeId=@EmployeeID


 


     


      UNION ALL


 


      Select E.EmployeeId,FirstName + ' ' + LastName as  EmpName


      From Employees  E,GetEmployee G


      Where E.ReportsTo =G.EmployeeId


    )


 


Select *


From GetEmployee


 

Wednesday, April 7, 2010

Get date for specified day of month in asp.net

'This code can be used when you want to find any specific date based on day of month
'like first monday of month,second tues day of month etc.


'declare first day of month
Dim M As String = "9"
Dim Y As String = "2011"
Dim fdm As DateTime = Convert.ToDateTime(M & "/01/" & Y)
'if suppose you have to find second friday of a month then use
fdm = fdm.AddDays(7) 'so that you will get a date of second week
'then loop to find the day specified as shown below
While Not fdm.DayOfWeek.ToString().ToLower().Contains("friday")
fdm = fdm.AddDays(1) 'move forward one day untill u get the specified Day
End While

lblDate.Text = fdm.ToString()

'similarly add 11 days for 3rd day, 21 days for 4th day.
'for first day do not add any day