Question : SQL Function

I'm trying to write a Function for a SQL table that returns Leave Balances and Sick Balances for each row in the table. I'm sure what to do when it comes to returning each individual employees balances.
Code Snippet:
1:
2:
3:
4:
Select sum(YTD_LV_ANNUAL_EARNED - YTD_LV_VACATION_TAKEN)FROM dbo.Employee 


Select sum(YTD_LV_SICK_EARNED - YTD_LV_SICK)FROM dbo.Employee

Answer : SQL Function

Hi Kita,

You could have a seperate view if you didn't want to display everything.  But if you wanted to add them here it would be something like;

YTD_LV_COMP_EARNED AS [COMPTIME EARNED YTD], YTD_LV_HLDY_EARNED_KH AS [HOLIDAY COMP EARNED YTD],
                      YTD_LV_COMP_TAKEN AS [COMPTIME TAKEN YTD], YTD_LV_COURT_COMP_EARND AS [COURT COMPTIME EARNED YTD],
                      LAST_INITIALS AS [NAME:], EMPLOYEE_CODE AS [CODE:], ASSIGNMENT AS [ASMT:], SCHDL_PLATOON AS [PLATOON:], SCHDL_SHIFT AS [SHIFT:],  sum(YTD_LV_SICK_EARNED - YTD_LV_SICK) as [SICK], sum(YTD_LV_ANNUAL_EARNED - YTD_LV_VACATION_TAKEN) as [VACATION]:  FROM  dbo.Employee
group by YTD_LV_COMP_EARNED, YTD_LV_HLDY_EARNED_KH,  YTD_LV_COMP_TAKEN, --continue group by for each column not using an aggregate.

Are you doing this for 1 employee (I don't see a where clause, how are you going to distinguish which empoyee is which?)
 

Random Solutions  
 
programming4us programming4us