I'm setting a SSRS Report with no Mandatory fields, Need Multiple values.
As per the site https://www.mssqltips.com/sqlservertip/3502/allow-null-value-in-multi-value-report-parameter-in-sql-server-reporting-services/
, still the client needs the output without providing any input, i.e, If there is 10 parameters, we need the output based upon selecting the 3 or 4 or any number of other parameters.
I will the query which is done as per
https://www.tutorialgateway.org/sql-query-to-select-all-if-parameter-is-empty-or-null/
check this Line
WHERE Occupation = IIF(@Occupation IS NULL, Occupation, @Occupation)
This is used in my code too.
SELECT [Order].[PartNumber],
[Order].[BuildCode],[Order].[Product],[Order].[AssemblyUnitName],[Order].[ProductionStatus] ,
SUM([Order].[QTY]) AS [QTY] FROM (SELECT [Order].[PartNumber],[Order].[AssemblyUnitName],[Order].[BuildCode] ,
CASE WHEN
[Order].[BuildCode] LIKE '%-230B-%' THEN
CASE WHEN
[Order].[BuildCode] LIKE '%-HIGH-%' THEN '230B-HIGH' WHEN [Order].[BuildCode] LIKE '%-LOW-%' THEN '230B-LOW'
ELSE '230B-SPORT' END
ELSE
CASE WHEN
[Order].[BuildCode] LIKE '%-0TAL-%' THEN 'NCAP-0T' WHEN [Order].[BuildCode] LIKE '%-AURA-%' THEN 'NCAP-AURA' WHEN [Order].[BuildCode] LIKE '%-DUNE-%' THEN 'NCAP-DUNE' WHEN [Order].[BuildCode] LIKE '%-24TK-%' THEN 'NCAP-24TK' WHEN [Order].[BuildCode] LIKE '%-COST-%' THEN 'NCAP-COSTA' ELSE 'NCAP-2T'
END END
+CASE WHEN
[Order].[AssemblyUnitName] ='230B FS RH MAIN' THEN '-RH'
WHEN [Order].[AssemblyUNitName] ='230B FS LH MAIN' THEN '-LH'
WHEN [Order].[AssemblyUNitName] ='230B RSB 40 MAIN' THEN '-RSB40'
WHEN [Order].[AssemblyUNitName] ='230B RSB 60 MAIN' THEN '-RSB60'
WHEN [Order].[AssemblyUNitName] ='230B RSB 100 MAIN' THEN '-RSB100'
WHEN [Order].[AssemblyUNitName] ='230B RSC 100 MAIN' THEN '-RSC100'
END AS [Product] ,
CASE WHEN
[Order].[ProcessStatus]>=50 AND [Order].[ProductionStatus]>=100 THEN 'FG'
WHEN MAX([Operation2].[Status]) IS NULL THEN 'FG'
WHEN [Order].[ProcessStatus]>=20 OR [Order].[ProductionStatus]>=20 THEN 'WIP' END AS [ProductionStatus] ,
1.0 AS [QTY] ,
SUBSTRING('>= CAST(CAST({FN NOW()} AS DATETIME)-60.2430555555555556',0,0) AS 'UNWANTED'
FROM [Order] WITH (NOLOCK) LEFT JOIN [Operation] AS [Operation2] WITH (NOLOCK) ON [Order].[Id]=[Operation2].[OrderId] AND [Operation2].[OperationTemplateReference]<>1039 AND [Operation2].[Status]<>'F'
WHERE
[Order].[PartNumber] in (IIF(@PartNumber IS NULL, [Order].[PartNumber], @PartNumber) )
and [Order].[BuildCode] in( IIF(@BuildCode IS NULL, [Order].[BuildCode], @BuildCode) )
and [Order].[AssemblyUnitName] in (IIF(@AssemblyUnitName IS NULL, [Order].[AssemblyUnitName], @AssemblyUnitName) )
GROUP BY
[Order].[Id],[Order].[OrderNumber],
[Order].[PartNumber],[Order].[BuildCode],
[Order].[AssemblyUnitName],
[Order].[IsScrap],[Order].[ProcessStatus],
[Order].[ProductionStatus]) AS [Order] GROUP
BY [Order].[PartNumber],
[Order].[BuildCode],[Order].[Product],
[Order].[AssemblyUnitName],
[Order].[ProductionStatus] ORDER BY [Order].
[BuildCode] OPTION (MAXDOP 2, MAX_GRANT_PERCENT=10)
Expected Output: SSRS Report Generation without selecting the parameters. If there is any wrong in the where condition of the query, please brainstorm me.
NOLOCK
here? Are you "ok" with incorrect result sets based on dirty reads, or reading difference versions of the same row in a single scan? – LarnuSTRING_SPLIT
. – LarnuWHERE (@PartNumber IS NULL OR [Order].[PartNumber] IN (@PartNumber))
and don't have any issues – Alan Schofield