1

这是我得到所有答案的唯一地方;)

我要选择:

SELECT 
    RTRIM(LTRIM(il.Num_bloc)) AS Bloc, 
    RTRIM(LTRIM(il.num_colis)) AS Colis,
    cd.transporteur AS Coursier, 
    cd.origine AS Origine, 
    cd.destination AS Destinataire,
    cd.adresse AS [Adresse Destinataire], 
    cd.poids AS Poids, 
    il.Signataire, il.num_cin AS CIN, il.date_livraison AS [Date Livraison]
FROM  
    dbo.cd 
INNER JOIN 
    dbo.il ON cd.bloc = il.Num_bloc AND dbo.cd.colis = dbo.il.num_colis
WHERE 
    (il.Num_bloc = RTRIM(LTRIM(@ParamBloc))) 
    AND (il.num_colis = RTRIM(LTRIM(@ParamColis)))

如果用户将以太币@ParamBloc@ParamColis

4

1 回答 1

0

尝试使用 IsNull() 函数。

一个简单的查询会像这样

Select * from yourTable
Where
  Num_bloc = ISNULL(@ParamBloc, Num_block) AND
  num_colis = ISNULL(@ParamColis, num_colis)

如果 @parameter Bloc 或 Colis 为空,则第二个参数将使表达式为 true。此查询对于这两个参数的所有 4 种可能组合都很有用。

于 2012-04-17T13:51:39.340 回答