How to convert the SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fahhad
    New Member
    • Feb 2013
    • 4

    How to convert the SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

    How to convert the following SQL-C# logic to syntactically-correct SQL code (SQL Server 2005)?

    "Descriptio n", "LeaveType" , "MonthlyMaxLeav e", "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 "Descriptio n" 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.



    Code:
    USE [Emp1]
    GO
    
    
    CREATE FUNCTION [dbo].[Leave] 
    (  
       @EmployeeID INT    
    )
    RETURNS INT  
    AS  
    
    BEGIN 
    
    DECLARE	@PayLeave INT,
    	@NonPayLeave INT;
    
    SET @PayLeave = 0;
    SET @NonPayLeave = 0;
    
    RETURN
    (
    	SELECT
    	IF((ImDescription == "Sick") AND (ImLeaveType == "Yearly"))
    	{
    		IF((ImMonthlyMaxLeave > 1) OR (ImYearlyMaxLeave > 10 ))
    		{
    			@NonPayLeave = @NonPayLeave + 1;
    			PRINT @NonPayLeave;
    		}		
    		ELSE
    		{	
    			@PayLeave = @PayLeave + 1;
    		    PRINT @PayLeave;
    		}
    	}
    )
    
    END
    
    
    
    --PRINT dbo.Leave('123')
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This is not a code writing service but if you post your attempt at the conversion, we can help guide you to a solution.

    Comment

    Working...