Click here to Skip to main content
11,805,604 members (62,744 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET SQL , +
How to convert the following SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

"Description", "LeaveType", "MonthlyMaxLeave", "YearlyMaxLeave" are the column names in the table EmpTab.

I have written a basic logic to calculate the PayLeave and NonPayLeave, and to display its final values. Assume that the fields "Description" and "LeaveType" always contains the values "Sick" and "Yearly" respectively. Please do not worry about the data in the table. The field values in the table may be customized as per the requirements.

Just correct the syntax in the code so as to meet the SQL standards, as well as to display the PayLeave and NonPayLeave values based on the calculation logic shown below.
USE [Emp1]
CREATE FUNCTION [dbo].[Leave] 
   @EmployeeID INT    
    DECLARE	@PayLeave INT,
    	@NonPayLeave INT;
    SET @PayLeave = 0;
    SET @NonPayLeave = 0;
        IF((ImDescription == "Sick") AND (ImLeaveType == "Yearly"))
            IF((ImMonthlyMaxLeave > 1) OR (ImYearlyMaxLeave > 10 ))
            	@NonPayLeave = @NonPayLeave + 1;
            	PRINT @NonPayLeave;
            	@PayLeave = @PayLeave + 1;
                PRINT @PayLeave;
--PRINT dbo.Leave('123')
Posted 14-Mar-13 20:46pm
Edited 14-Mar-13 21:09pm
(no name)17.8K
Karthik Harve at 15-Mar-13 3:10am
[Edit] pre tags added.
Maciej Los at 6-Apr-13 16:55pm
Please, be more specific and provide more details.
Are you trying to count NonPayLeave and PayLeave for employee with EmployeeID?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 3,265
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100