在具有空值的参数中选择多值以及NULL值

时间:2017-04-21 16:28:05

标签: sql stored-procedures reporting-services ssrs-2012 ssrs-tablix

所以这有点令人困惑。我已经有了一个存储过程。我有报告,其中有5到6个参数。我希望它以这样一种方式运行报告:您应该能够在下拉列表中选择多个值并保持可选(不选择任何值)。另一件事是我的参数值也有NULL值,我已用NA替换它。我尝试在参数属性中使用默认值进行某些选择,但是对于某些选择它没有。我仍然是SSRS的中间人。任何帮助将不胜感激。 谢谢

3 个答案:

答案 0 :(得分:0)

我假设您已经创建了一个函数并在存储过程中使用该函数来使该存储过程成为多值选择。

在您的函数中,无论哪个变量具有varchar或任何字符串数据类型,都将其大小设置为MAX,如varchar(max),并在参数的存储过程中执行相同的操作。

这个原因背后的原因:当您提供数据类型为varchar(255)时,它将只取一个255字符的值,如果您的值字符超过该限制,那么它将截断超过该限制的数据。你正在使它们多选,所以你可能需要将它们作为varchar(max)。

在参数的存储过程中也将大小设置为Max。

注意:Varchar(Max)只是一个例子。您可以为函数和存储过程中使用的任何字符串数据类型提供max。

让我知道它是否有效..

答案 1 :(得分:0)

   ALTER PROCEDURE [dbo].[sp_PIMSelect_AJ_Test] 

@network nvarchar(MAX),
--@provider nvarchar(MAX),
--@affiltype varchar(MAX),
--@npi varchar(MAX),
--@tin varchar(MAX),
--@inprovtype varchar (MAX),
@SLG nvarchar(MAX),
@county nvarchar(MAX),
@zip nvarchar(Max),
@specCode nvarchar(Max),
@affiltype nvarchar(Max),
@contract nvarchar(Max)

    AS

    SET NOCOUNT ON;

select * from ( 
    select 
distinct    P1.Provid as PIMProviderID,
            P.NetworkName,
            --COALESCE(pa.affiltype, 'NA') as affiliationtype,
            PP1.planprovid as ProviderPlanProvID,
            p1.lastname as ProviderLastName,
            p1.Firstname as ProviderFirstName,
            P1.Profdesig as ProviderTitle,
            p1.intprovtype as ProviderIntProvType,
            COALESCE(NULLIF(P1.Provtype, ''), 'NA') as ProviderProvType,
            XP1.Description as ProviderTypeDescription,
            COALESCE(ps1.specialtycode, 'NA') as ProviderSpecialtyCode,
            ps1.DirectorySpec as ProviderSpecialityDescription,
            ps1.spectype as ProviderSpecType,
            p1.CredType as ProviderCredType,
            p1.phyaddress1 as ProviderPhyAddress1,
            p1.phyaddress2 as ProviderPhyAddress2,
            p1.phycity as ProviderPhyCity,
            p1.phystate as ProviderPhyState,
            p1.phyzipcode as ProviderPhyZipCode,
            p1.phycounty as ProviderPhyCounty,
            p1.address1 as ProviderMailingAddress1,
            p1.address2 as ProviderMailingAddress2,
            p1.city as ProviderMailingCity,
            p1.state as ProviderMailingState,
            p1.Zipcode as ProviderMailingZip,
            p1.county as ProviderMailingCounty,
            COALESCE(NULLIF(p1.TIN, ''),'0') as ProviderTIN,
            COALESCE(NULLIF(p1.NPI, ''),'0') as ProviderNPI,


            pa.Affiltype as AffilType,
            p.provid as AffilPIMProviderID,
            PP.planprovid as AffiliationPlanProvID,
            p.Lastname as AffilLastName,
            p.Firstname as AffilFirstName,
            COALESCE(p.intprovtype, 'NA') as AffilIntProvType,
            XP.Description as AffiliationTypeDescription,
            ps.specialtycode as AffilSpecialtyCode,
            ps.spectype as AffilSpecType,
            ps.directoryspec as AffilSpecialtyDescription,
            PA.IntDirLocation as AffilDirLocation,
            p.phyaddress1 as AffilPhyAddress1,
            p.phyaddress2 as AffilPhyAddress2,
            p.phycity as AffilPhyCity,
            p.phystate as AffilPhyState,
            COALESCE(NULLIF(p.phyzipcode, ''), 'NA') as AffilPhyZipCode,
            COALESCE(NULLIF(p.phycounty, ''), 'NA') as AffilPhyCounty,
            p.address1 as AffilMailingAddress1,
            p.address2 as AffilMailingAddress2,
            p.city as AffilMailingCity,
            p.state as AffilMailingState,
            p.Zipcode as AffilMailingZip,
            p.county as AffilMailingCounty,
            COALESCE(NULLIF(p.TIN,  ''),'0') as AffilTIN,
            COALESCE(NULLIF(p.NPI, ''),'0') as AffilNPI,
            COALESCE(CI.contractid, 'NA') as AffilContractID,
            COALESCE(C.description, 'NA') as AffilContractDesc


     from ProviderManager.dbo.Provider p
     left join ProviderManager.dbo.XProviderTypes XP on P.Provtype = XP.[Provider Type_ID]
     left join ProviderManager.dbo.planprovinfo PP on P.Provid = PP.provid
    left join ProviderManager.dbo.provspecialty ps on ps.provid = p.Provid
    left join ProviderManager.dbo.Affiliation pa on pa.affilid= p.Provid
    left join ProviderManager.dbo.provider p1 on p1.provid = pa.provid
    left join ProviderManager.dbo.CredApproval CA on P1.NPI = CA.NPI
    left join ProviderManager.dbo.planprovinfo PP1 on P1.Provid = PP1.provid
    left join ProviderManager.dbo.provspecialty ps1 on p1.Provid = ps1.provid
    left join ProviderManager.dbo.XProviderTypes XP1 on P1.Provtype = XP1.[Provider Type_ID]
    left join ProviderManager.dbo.contractinfo CI on P1.Provid = CI.provid and P.intprovtype = 'Group' and P.Provid = CI.affilid
    left join ProviderManager.dbo.Contract C on CI.contractid 
               COLLATE SQL_Latin1_General_CP1_CI_AS = C.contractid COLLATE SQL_Latin1_General_CP1_CI_AS) cte
    WHERE  
    cte.ProviderIntProvType IN ('Facility', 'Physician')
    and (cte.NetworkName COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@network, ',')))
    and (cte.AffilPIMProviderID IN (Select Value from VIB_Extracts.dbo.FnSplit(@SLG, ',')))
    and (cte.AffilPhyCounty COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@county, ','))OR (@county = 'NA'))
    and (cte.Affilphyzipcode COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@zip, ',')) OR (@zip = 'NA'))
    and (cte.ProviderSpecialtyCode COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@specCode, ',')))
    and (cte.ProviderProvType COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@affiltype, ',')))
    and (cte.AffilContractID COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@contract, ',')))
    --and (cte.providerNPI COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@npi,','))) 
    --and (cte.providerTIN COLLATE DATABASE_DEFAULT IN (Select Value from VIB_Extracts.dbo.FnSplit(@TIN,',')))
    Order by Cte.ProviderLastName

答案 2 :(得分:0)

    USE [VIB_Extracts]
GO
/****** Object:  UserDefinedFunction [dbo].[FnSplit]    Script Date: 4/29/2017 9:59:16 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER FUNCTION [dbo].[FnSplit]
(
@List nvarchar(MAX),
@SplitOn nvarchar(5)
)  
RETURNS @RtnValue table 
(

Id int identity(1,1),
Value nvarchar(100)
) 
AS  
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin 
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1))) 
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End 

Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END