Здесь я создал #temp Table и использую функцию IFNULL, если данные равны NULL, тогда я заменил на 1
ISNULL(prog.ProgramOwner,1) ProgramOwner,
ISNULL(ProductFamily,1) ProductFamily,
ISNULL(CostCenter,1) CostCenter ,
, после этого я использую case, если data равен 1, тогда показать данные, вставленные в таблицу
case when ProgramOwner ='1' then NULL else ProgramOwner end as ProgramOwner,
case when ProductFamily ='1' then NULL else ProductFamily end as ProductFamily,
case when CostCenter ='1' then NULL else CostCenter end as CostCenter,
Вот запрос
Declare @InFromDate DATETIME = '2019-08-01',
@InToDate DATETIME= '2019-08-31',
@InEmployeeDomainName NVARCHAR(50) = null,--'C3ITDOMAIN\test3',--'C3ITDOMAIN\test3,C3ITDOMAIN\test7'
@InBillableType INT = null,
@InLogStatus INT = null,
@InManagerName NVARCHAR(max) = null,--'Test Two',-- 'Test Two',
@InTaskID NVARCHAR(max) = null,--'2039,2040',-- '2039,2040',
@InProgramID NVARCHAR(max) = null,--null,-- '1024,2015',
@InProgramOwner NVARCHAR(max) = null,--'Dhiraj kulkarni',-- 'Dhiraj kulkarni',
@InProductFamily NVARCHAR(max) = 'cipla',--'Woodies',-- 'Woodies',
@InCostCenter NVARCHAR(max) = null,--'ABD',-- 'ABD',
@InDepartmentID NVARCHAR(max) = null,-- '2',
@InPageSize BIGINT = 10,
@InPageIndex INT = 2,
@InSortingKey VARCHAR(100) = 'ROW',
@InIsAscending TINYINT = 2
IF OBJECT_ID('tempdb..#Panging_Data_List') IS NOT NULL
DROP TABLE #Panging_Data_List
CREATE TABLE #Panging_Data_List
(ProgramID [INT],
ProgramName [nvarchar](max),
ProgramOwner [nvarchar](max),
ProductFamily [nvarchar](max),
CostCenter [nvarchar](max),
DepartmentName [nvarchar](max),
EmployeeCode [nvarchar](max),
EmployeeName [nvarchar](max),
EmployeeDomainName [nvarchar](max),
ManagerName [nvarchar](max),
TaskName [nvarchar](max),
IsBillable [nvarchar](max),
IsMachineCostInvolve[nvarchar](max),
MachineCostPerHour DECIMAL(18,2),
MachineHours DECIMAL(18,2),
MachineCost DECIMAL(18,2),
IsResourceCostInvolve [nvarchar](max),
HourlyResourceCost DECIMAL(18,2),
TotalResourceCost DECIMAL(18,2),
TotalHrs DECIMAL(18,2),
[Row] [INT],
)
;WITH CTE AS
(
Select
prog.ProgramID,
prog.ProgramName,
ISNULL(prog.ProgramOwner,1) ProgramOwner,
ISNULL(ProductFamily,1) ProductFamily,
ISNULL(CostCenter,1) CostCenter ,
DepartmentName,
logmaster.EmployeeCode,
logmaster.EmployeeName,
logmaster.EmployeeDomainName,
ManagerName,
TaskName,
(CASE WHEN IsBillable = 1 THEN 'Yes' WHEN IsBillable = 0 THEN 'NO' END) as IsBillable ,
(CASE WHEN IsMachineCostInvolve = 1 THEN 'Yes' WHEN IsMachineCostInvolve = 0 THEN 'NO' END) as IsMachineCostInvolve,
MachineCostPerHour,
sum(logs.MachineHours) MachineHours,
(CASE When IsMachineCostInvolve = 1 then (MachineCostPerHour * sum(MachineHours)) else null END) as MachineCost,
(CASE WHEN IsResourceCostInvolve = 1 THEN 'Yes' WHEN IsResourceCostInvolve = 0 THEN 'NO' END) as IsResourceCostInvolve,
rcost.HourlyResourceCost,
(CASE When IsResourceCostInvolve = 1 then ( rcost.HourlyResourceCost * sum(LoggedHours)) else null END) as TotalResourceCost,
sum(logs.LoggedHours) TotalHrs ,
ROW_NUMBER() OVER (ORDER BY prog.ProgramID ) AS Row
from [dbo].defProgramMaster prog
left outer join datTaskLogTransactionDetails logs
ON prog.ProgramID = logs.ProgramID
inner JOIN datTaskLogMaster logmaster
ON logmaster.TaskLogID = logs.TaskLogID
Left JOIN defTaskMaster taskmaster
ON taskmaster.TaskID= logs.TaskID
left outer JOIN defResourceCosts rcost
on rcost.EmployeeCode =logmaster.EmployeeCode and rcost.DepartmentID= logmaster.DepartmentID
WHERE LogDate BETWEEN convert(varchar(10), @InFromDate, 23) AND convert(varchar(10), @InToDate, 23)
and IsBillable = ( CASE WHEN @InBillableType IS NULL THEN IsBillable ELSE @InBillableType END)
and LogStatus = ( CASE WHEN @InLogStatus IS NULL THEN LogStatus ELSE @InLogStatus END)
and logmaster.EmployeeDomainName IN ( (SELECT Item from [dbo].[SplitString](ISNULL(@InEmployeeDomainName,EmployeeDomainName),',')))
and logmaster.ManagerName IN (SELECT Item from [dbo].[SplitString](ISNULL(@InManagerName,ManagerName),','))
and logs.TaskID IN (SELECT Item from [dbo].[SplitString](ISNULL(@InTaskID,logs.TaskID),','))
and logs.ProgramID IN (SELECT Item from [dbo].[SplitString](ISNULL(@InProgramID,logs.ProgramID),','))
and logmaster.DepartmentID IN (SELECT Item from [dbo].[SplitString](ISNULL(@InDepartmentID,logmaster.DepartmentID),','))
group by
prog.ProgramID,
prog.ProgramName,
prog.ProgramOwner,
prog.ProductFamily,
CostCenter,
DepartmentName,
logmaster.EmployeeCode,
logmaster.EmployeeName,
logmaster.EmployeeDomainName,
ManagerName,
TaskName,
IsBillable,
IsMachineCostInvolve,
MachineCostPerHour,
IsResourceCostInvolve,
HourlyResourceCost,
IsMachineCostInvolve,
IsResourceCostInvolve
)
insert into #Panging_Data_List
SELECT
ProgramID, ProgramName,
case when ProgramOwner ='1' then NULL else ProgramOwner end as ProgramOwner,
case when ProductFamily ='1' then NULL else ProductFamily end as ProductFamily,
case when CostCenter ='1' then NULL else CostCenter end as CostCenter,
DepartmentName, EmployeeCode,
EmployeeName, EmployeeDomainName, ManagerName, TaskName, IsBillable, IsMachineCostInvolve,
MachineCostPerHour, MachineHours, MachineCost, IsResourceCostInvolve, HourlyResourceCost, TotalResourceCost,
TotalHrs, ROW_NUMBER() OVER (ORDER BY ProgramID ) AS Row
FROM CTE
WHERE (ProgramOwner IN (SELECT Item from [dbo].[SplitString](ISNULL(@InProgramOwner,ProgramOwner),','))
AND ProductFamily IN (SELECT Item from [dbo].[SplitString](ISNULL(@InProductFamily,ProductFamily),','))
AND CostCenter IN (SELECT Item from [dbo].[SplitString](ISNULL(@InCostCenter,CostCenter),',')))
select * from #Panging_Data_List