how to select mutiple column match with a single value other column values be null?
this is my table value like
masterid dateorder Ist IInd IIIrd IVth Vth VIth
------------------------------------------------------------------------
08mcaao1 1 MC1701 MC1702 MC1703 Mc1704 Mc1705 Mc1701
08mcaao1 2 MC1701 MC1702 MC1703 Mc1703 Mc1705 Mc1702
08mcaao1 3 MC1701 MC1703 MC1703 Mc1704 Mc1705 Mc1701
if i'm select this table based on column value like MC1701
the result must be this form
masterid dateorder Ist IInd IIIrd IVth Vth VIth
-------------------------------------------------------------------
08mcaao1 1 MC1701 - - - - Mc1701
08mcaao1开发者_Python百科 2 MC1701 - - - - -
08mcaao1 3 MC1701 - - - - Mc1701
Use a CASE statement on fields Ist, IInd, IIIrd, IVth ,Vth, VIth to compare it against your criteria. If it matches with your criteria display the value otherwise display -
declare @param as nvarchar(100)
set @param = 'whatever'
select
...
case when Ist = @param then Ist else '-' end 'Ist'
...
where Ist = @param or ...
精彩评论