I am getting an error while running this code - Incorrect syntax near the keyword 'IF'. I need the output through function only with table return . CREATE FUNCTION [dbo].[fnct_rpt_ActiveHC_WithoutGrp_tarun1] ( @adid1 varchar(25), @number int ) RETURNS TABLE AS RETURN IF @adid1 in ( 'tachakr','BEULA','NI345519') BEGIN SELECT * FROM OD_SAP.dbo.ty_rpt_ActiveHC_WithoutGrp a JOIN [BI_Control].[dbo].[tbl_BI_AccessMatrix_ADIDcc] b ON a.CostCode = b.cc JOIN [BI_Control].[dbo].[tbl_BI_AccessMatrixMaster] C ON b.ADID = c.ADID AND C.IsActive = 1 END ELSE BEGIN SELECT EmployeeID, EmployeeName, DOB, Gender, DOJ, LevelCode, TEDRole, OrgRoleDesc AS OrgRole, Designation, Productive, Billable, Phase, TraineeType, BenchReason, ShiftCode, EmpLocation, BossID, BossName, OrgID, ProcessName AS OrgName, OrgLocation, CostCode, CompCode, GroupName, BUHead, Site, ForDate, ETL_DateTime FROM OD_SAP.dbo.ty_rpt_ActiveHC_WithoutGrp a JOIN [BI_Control].[dbo].[tbl_BI_AccessMatrix_ADIDcc] b ON a.CostCode = b.cc JOIN [BI_Control].[dbo].[tbl_BI_AccessMatrixMaster] C ON b.ADID = c.ADID AND C.IsActive = 1 where b.ADID = @adid1 AND b.ReportID = @number END