在CASE WHEN中满足特定条件时删除列 [英] Remove a column when meet a certain condition in CASE WHEN
本文介绍了在CASE WHEN中满足特定条件时删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下SQL语句,我想在满足条件时删除某个列。以下是我的SQL语句:
Hi, I have the following SQL statement in which I want to remove a certain column when a condition is met. Below are my SQL statement:
CASE @p_ReportType WHEN 1 THEN NULL WHEN ISNULL(@p_ReportType, 0) THEN row_number() OVER (ORDER BY EventId desc)+1 END AS MeasurementGroupId
对于上面的场景,当@p_ReportType为1时,除去MeasurementGroupId,否则保留MeasurementGroupId。任何帮助都表示赞赏。
For the above scenario, when the @p_ReportType is 1 then the MeasurementGroupId is removed else the MeasurementGroupId is remained. Any helps are appreciated.
推荐答案
上面的代码不会删除任何列!它评估条件列表并返回多个可能的结果表达式之一。
请参阅:
CASE(sql) [ ^ ]
Above code does not remove any column! It "evaluates a list of conditions and returns one of multiple possible result expressions".
See:
CASE (sql)[^]
这篇关于在CASE WHEN中满足特定条件时删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文