动态命令文本到 Reporting Services
Dynamically command text into Reporting Services
我在 SQL Server Reporting Services 和 Visual Studio .NET 创建的报告中遇到问题。
我有一个字符串类型的字段,有时在数据库中可以为 NULL,这使我无法使用 LIKE '%%' 进行简单搜索。我的想法是在 CommandText
IIF 报告中插入一个子句,这样如果该字段为 NULL,实际上我指定为默认值 '%',则不会进行任何研究,否则将添加到列表中LIKE 搜索的字段。
该字段是 Parameters.NOTE
和 IIF
我认为会使用的子句:
IIF (Trim (Parameters! NOTE.Value) = "%", "", "AND AD.NOTE ILIKE%" + Parameters! NOTE.Value + "% ").
主要问题是报告没有给我任何错误,但即使我 returns 也没有价值。我看不懂怎么办。
<Query>
<DataSourceName>DS1</DataSourceName>
<CommandText>
SELECT
ANG.Cognome || ' ' || ANG.Nome AS NomeDipendente,
R.Descrizione AS Reparto,
AD.Anno,
AD.Mese,
AD.DataInserimento,
TP.Descrizione AS TipoPagamento,
AD.Importo,
AD.Note,
getRetribuzioneDipendente(AD.Dipendente, AD.Mese, AD.Anno) AS Retribuzione,
(SELECT
SUM(AD1.Importo)
FROM
AccontiDipendenti AD1
WHERE
AD1.Dipendente = AD.Dipendente AND
AD1.Mese = AD.Mese AND
AD1.Anno = AD.Anno AND
AD1.DataInserimento <= AD.DataInserimento
)
AS Acconti,
U.NickName
FROM
AccontiDipendenti AD
INNER JOIN
AnagraficaDipendenti ANG ON (AD.Dipendente = ANG.CodiceDipendente)
INNER JOIN
MansioniDipendenti MD ON (ANG.CodiceMansione = MD.CodiceMansione)
INNER JOIN
Reparti R ON (MD.CodiceReparto = R.CodiceReparto)
INNER JOIN
Utenti U ON (AD.UserName = U.UserName)
INNER JOIN
TipiPagamento TP ON (AD.CodiceTipoPag = TP.CodiceTipoPag)
WHERE
ANG.CodiceDipendente ILIKE COALESCE(@CODICEDIPENDENTE, '%') AND
R.CodiceReparto ILIKE COALESCE(@CODICEREPARTO, '%') AND
AD.CodiceTipoPag ILIKE COALESCE(@CODICETIPOPAG, '%') AND
to_date(to_char(AD.DataInserimento, 'DD-MM-YYYY'), 'DD-MM-YYYY') >= to_date(@INIZIO, 'DD-MM-YYYY') AND
to_date(to_char(AD.DataInserimento, 'DD-MM-YYYY'), 'DD-MM-YYYY') <= to_date(@FINE, 'DD-MM-YYYY')
IIF(Trim(Parameters!NOTE.Value)="%", "" , " AND AD.NOTE ILIKE %" + Parameters!NOTE.Value + "%")
</CommandText>
<QueryParameters>
<QueryParameter Name="NOTEASSEGNO">
<Value>=IIF(Trim(Parameters!NOTE.Value)="%", "%" , "%" + Parameters!NOTE.Value + "%")</Value>
</QueryParameter>
<QueryParameter Name="CODICEDIPENDENTE">
<Value>=Parameters!CODICEDIPENDENTE.Value</Value>
</QueryParameter>
<QueryParameter Name="CODICEREPARTO">
<Value>=Parameters!CODICEREPARTO.Value</Value>
</QueryParameter>
<QueryParameter Name="INIZIO">
<Value>=Parameters!DATAINIZIO.Value</Value>
</QueryParameter>
<QueryParameter Name="FINE">
<Value>=Parameters!DATAFINE.Value</Value>
</QueryParameter>
<QueryParameter Name="CODICETIPOPAG">
<Value>=Parameters!CODICETIPOPAG.Value</Value>
</QueryParameter>
</QueryParameters>
</Query>
使用参数传递给query.Suppose参数名称是@Note
。将 @Note
值设置为 Parameters!NOTE.Value
。并确保您在报告和查询中的两个地方都设置了参数 Null
by dfault。你可以做这样的条件,
AND (@Note IS NULL OR AD.NOTE LIKE +'%'@Note+'%')
这将首先检查@Note 值是否为空,如果为空,则它不会进入下一个过滤器,如果不为空,则它将进入 Like
的过滤器。
我在 SQL Server Reporting Services 和 Visual Studio .NET 创建的报告中遇到问题。
我有一个字符串类型的字段,有时在数据库中可以为 NULL,这使我无法使用 LIKE '%%' 进行简单搜索。我的想法是在 CommandText
IIF 报告中插入一个子句,这样如果该字段为 NULL,实际上我指定为默认值 '%',则不会进行任何研究,否则将添加到列表中LIKE 搜索的字段。
该字段是 Parameters.NOTE
和 IIF
我认为会使用的子句:
IIF (Trim (Parameters! NOTE.Value) = "%", "", "AND AD.NOTE ILIKE%" + Parameters! NOTE.Value + "% ").
主要问题是报告没有给我任何错误,但即使我 returns 也没有价值。我看不懂怎么办。
<Query>
<DataSourceName>DS1</DataSourceName>
<CommandText>
SELECT
ANG.Cognome || ' ' || ANG.Nome AS NomeDipendente,
R.Descrizione AS Reparto,
AD.Anno,
AD.Mese,
AD.DataInserimento,
TP.Descrizione AS TipoPagamento,
AD.Importo,
AD.Note,
getRetribuzioneDipendente(AD.Dipendente, AD.Mese, AD.Anno) AS Retribuzione,
(SELECT
SUM(AD1.Importo)
FROM
AccontiDipendenti AD1
WHERE
AD1.Dipendente = AD.Dipendente AND
AD1.Mese = AD.Mese AND
AD1.Anno = AD.Anno AND
AD1.DataInserimento <= AD.DataInserimento
)
AS Acconti,
U.NickName
FROM
AccontiDipendenti AD
INNER JOIN
AnagraficaDipendenti ANG ON (AD.Dipendente = ANG.CodiceDipendente)
INNER JOIN
MansioniDipendenti MD ON (ANG.CodiceMansione = MD.CodiceMansione)
INNER JOIN
Reparti R ON (MD.CodiceReparto = R.CodiceReparto)
INNER JOIN
Utenti U ON (AD.UserName = U.UserName)
INNER JOIN
TipiPagamento TP ON (AD.CodiceTipoPag = TP.CodiceTipoPag)
WHERE
ANG.CodiceDipendente ILIKE COALESCE(@CODICEDIPENDENTE, '%') AND
R.CodiceReparto ILIKE COALESCE(@CODICEREPARTO, '%') AND
AD.CodiceTipoPag ILIKE COALESCE(@CODICETIPOPAG, '%') AND
to_date(to_char(AD.DataInserimento, 'DD-MM-YYYY'), 'DD-MM-YYYY') >= to_date(@INIZIO, 'DD-MM-YYYY') AND
to_date(to_char(AD.DataInserimento, 'DD-MM-YYYY'), 'DD-MM-YYYY') <= to_date(@FINE, 'DD-MM-YYYY')
IIF(Trim(Parameters!NOTE.Value)="%", "" , " AND AD.NOTE ILIKE %" + Parameters!NOTE.Value + "%")
</CommandText>
<QueryParameters>
<QueryParameter Name="NOTEASSEGNO">
<Value>=IIF(Trim(Parameters!NOTE.Value)="%", "%" , "%" + Parameters!NOTE.Value + "%")</Value>
</QueryParameter>
<QueryParameter Name="CODICEDIPENDENTE">
<Value>=Parameters!CODICEDIPENDENTE.Value</Value>
</QueryParameter>
<QueryParameter Name="CODICEREPARTO">
<Value>=Parameters!CODICEREPARTO.Value</Value>
</QueryParameter>
<QueryParameter Name="INIZIO">
<Value>=Parameters!DATAINIZIO.Value</Value>
</QueryParameter>
<QueryParameter Name="FINE">
<Value>=Parameters!DATAFINE.Value</Value>
</QueryParameter>
<QueryParameter Name="CODICETIPOPAG">
<Value>=Parameters!CODICETIPOPAG.Value</Value>
</QueryParameter>
</QueryParameters>
</Query>
使用参数传递给query.Suppose参数名称是@Note
。将 @Note
值设置为 Parameters!NOTE.Value
。并确保您在报告和查询中的两个地方都设置了参数 Null
by dfault。你可以做这样的条件,
AND (@Note IS NULL OR AD.NOTE LIKE +'%'@Note+'%')
这将首先检查@Note 值是否为空,如果为空,则它不会进入下一个过滤器,如果不为空,则它将进入 Like
的过滤器。