Sunday, 15 December 2013

Create FUNCTION TO find TAX in sqlserver

CREATE FUNCTION F_Get_IncommTaxx(@sal money) -- 2500000
RETURNS money
-- SELECT DBO.F_Get_IncommTaxx(300000)
AS
BEGIN
      DECLARE @R_sal MONEY=@sal-150000 -- 350000
      DECLARE @tax MONEY =0
       IF(@R_sal>0 AND @R_sal<=100000)
       BEGIN

            SET @tax=(@R_sal *10)/100
            SET @R_sal=@R_sal-100000
       END
       ELSE IF(@R_SAL>0)
       BEGIN
            SET @tax=(100000 *10)/100 -- 10000
            set @R_sal=@R_sal-100000  -- 250000

       END
       -- 20% slab
       if(@R_sal>0 AND @R_sal<=200000)
       BEGIN
            SET @tax=@tax+((@R_sal *20)/100)
            SET @R_sal=@R_sal-200000
       END
       ELSE IF(@R_SAL>0)
       BEGIN
            SET @tax=@tax+((200000 *20)/100) -- 50000
            SET @R_sal=@R_sal-200000  
       END
       
       -- 30% slab
       IF(@R_sal>0 )
       BEGIN
            SET @tax=@tax+((@R_sal *30)/100) -- 65500
       END
     
       
       RETURN @tax;
END


SET NUMBER of RECORDS per PAGE in SQLSERVER

PAGING in SQL SERVER

USE AdventureWorksDW
GO
CREATE PROC usp_paging(@NOOFRECORDS INT,@PAGENO INT)
AS
--EXEC usp_paging 10,2
BEGIN

DECLARE @STING INT=((@PAGENO-1)*@NOOFRECORDS)+1
DECLARE @ENDING INT=@NOOFRECORDS*@PAGENO
PRINT @STING
PRINT @ENDING
;WITH X AS(
SELECT *,DENSE_RANK() OVER (ORDER BY TIMEKEY)AS DENSERANK
,RANK() OVER (ORDER BY TIMEKEY) AS RANK,
ROW_NUMBER() OVER(PARTITION BY TIMEKEY ORDER BY TIMEKEY)AS ROWNUMBER  FROM FactFinance)
SELECT * FROM X WHERE ROWNUMBER=1 AND DENSERANK BETWEEN @STING AND @ENDING
ORDER BY TimeKey
END

Results:

EMP, DEPT Sample script

/****** Object:  Table [dbo].[DEPT]    Script Date: 19-05-2016 06:58:37 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET A...