Sql server 如何删除此案例陈述?

Sql server 如何删除此案例陈述?,sql-server,tsql,case,Sql Server,Tsql,Case,查询按原样工作,但是,我想知道是否有更好的方法来执行/编写查询。我想用一个外部应用程序,但它看起来不工作 编辑:为了更清楚,我正在尝试从SELECT语句中删除IIF(与CASE相同)。这就是您要查找的内容吗 select id, shelfno, sectionno, iif(tableA.shelfno = tableB.promono, itemdesc + ' Best Sale Right Now!', itemdesc), salesprice from

查询按原样工作,但是,我想知道是否有更好的方法来执行/编写查询。我想用一个外部应用程序,但它看起来不工作


编辑:为了更清楚,我正在尝试从SELECT语句中删除IIF(与CASE相同)。

这就是您要查找的内容吗

select id, shelfno, sectionno, 
       iif(tableA.shelfno = tableB.promono, itemdesc + ' Best Sale Right Now!', itemdesc),
       salesprice
from tableA
left join tableB on tableA.shelfno = tableB.promono

这就是你要找的吗

select id, shelfno, sectionno, 
       iif(tableA.shelfno = tableB.promono, itemdesc + ' Best Sale Right Now!', itemdesc),
       salesprice
from tableA
left join tableB on tableA.shelfno = tableB.promono

这就是你要找的吗

select id, shelfno, sectionno, 
       iif(tableA.shelfno = tableB.promono, itemdesc + ' Best Sale Right Now!', itemdesc),
       salesprice
from tableA
left join tableB on tableA.shelfno = tableB.promono

这就是你要找的吗

select id, shelfno, sectionno, 
       iif(tableA.shelfno = tableB.promono, itemdesc + ' Best Sale Right Now!', itemdesc),
       salesprice
from tableA
left join tableB on tableA.shelfno = tableB.promono

您可以在需要时使用CASE

case 
    tableB.promono is null then itemdesc
    else itemdesc + ' Best Sale Right Now!'
end

您可以在需要时使用CASE

case 
    tableB.promono is null then itemdesc
    else itemdesc + ' Best Sale Right Now!'
end

您可以在需要时使用CASE

case 
    tableB.promono is null then itemdesc
    else itemdesc + ' Best Sale Right Now!'
end

您可以在需要时使用CASE

case 
    tableB.promono is null then itemdesc
    else itemdesc + ' Best Sale Right Now!'
end

这假设左联接仅在
中使用,如果
表B中没有使用其他列(如果将所有列都使用别名,则会更清楚):-

或在Sql Server 2012中:-

SELECT id, shelfno, sectionno, itemdesc + CASE WHEN exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno) THEN ' Best Sale Right Now!'
    ELSE '' END as itemdesc,
    salesprice
FROM tableA

这假设左联接仅在
中使用,如果
表B中没有使用其他列(如果将所有列都使用别名,则会更清楚):-

或在Sql Server 2012中:-

SELECT id, shelfno, sectionno, itemdesc + CASE WHEN exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno) THEN ' Best Sale Right Now!'
    ELSE '' END as itemdesc,
    salesprice
FROM tableA

这假设左联接仅在
中使用,如果
表B中没有使用其他列(如果将所有列都使用别名,则会更清楚):-

或在Sql Server 2012中:-

SELECT id, shelfno, sectionno, itemdesc + CASE WHEN exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno) THEN ' Best Sale Right Now!'
    ELSE '' END as itemdesc,
    salesprice
FROM tableA

这假设左联接仅在
中使用,如果
表B中没有使用其他列(如果将所有列都使用别名,则会更清楚):-

或在Sql Server 2012中:-

SELECT id, shelfno, sectionno, itemdesc + CASE WHEN exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno) THEN ' Best Sale Right Now!'
    ELSE '' END as itemdesc,
    salesprice
FROM tableA

没有案子,没有IIF,按要求

SELECT id, shelfno, sectionno, itemdesc + iif(exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno),' Best Sale Right Now!','') as itemdesc,
    salesprice
FROM tableA

没有案子,没有IIF,按要求

SELECT id, shelfno, sectionno, itemdesc + iif(exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno),' Best Sale Right Now!','') as itemdesc,
    salesprice
FROM tableA

没有案子,没有IIF,按要求

SELECT id, shelfno, sectionno, itemdesc + iif(exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno),' Best Sale Right Now!','') as itemdesc,
    salesprice
FROM tableA

没有案子,没有IIF,按要求

SELECT id, shelfno, sectionno, itemdesc + iif(exists(
        select * 
        from tableB 
        where tableB.promono = tableA.shelfno),' Best Sale Right Now!','') as itemdesc,
    salesprice
FROM tableA



在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。在SQL Server 2012中,IIF是与CASE等效的速记。我错误地认为每个人都会知道这一点。抱歉。在SQL Server 2012中,IIF是与CASE等效的速记。我错误地认为每个人都会知道这一点。抱歉。在SQL Server 2012中,IIF是与CASE等效的速记。我错误地认为每个人都会知道这一点。对不起,不完全是。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您无法删除,因为您的结果是有条件的。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您无法删除,因为您的结果是有条件的。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您无法删除,因为您的结果是有条件的。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与案例相同)。您无法删除,因为您的结果是有条件的。我很抱歉。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您可能希望通过使用
itemdesc+IIF(tableB.promono为NULL,,,“Best Sale Right Now!”)来更改连接方式。
在我看来,它读起来更好一些。。但我不确定有没有办法取消这个条件。我很抱歉。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您可能希望通过使用
itemdesc+IIF(tableB.promono为NULL,,,“Best Sale Right Now!”)来更改连接方式。
在我看来,它读起来更好一些。。但我不确定有没有办法取消这个条件。我很抱歉。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您可能希望通过使用
itemdesc+IIF(tableB.promono为NULL,,,“Best Sale Right Now!”)来更改连接方式。
在我看来,它读起来更好一些。。但我不确定有没有办法取消这个条件。我很抱歉。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。您可能希望通过使用
itemdesc+IIF(tableB.promono为NULL,,,“Best Sale Right Now!”)来更改连接方式。
在我看来,它读起来更好一些。。但我不确定有没有办法取消这个条件。我很抱歉。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。我不明白为什么您试图避免使用
CASE
/
IIF
,因为它似乎是正确(最有效)的方法。我看不出“交叉应用”将如何产生比我建议的
exists()
更便宜的执行计划(特别是如果存在正确的索引来覆盖查询的话)-优化器将尝试将所有其他建议的解决方案转换为
exists()
无论如何……我深表歉意。在SQL Server 2012中,IIF是与大小写等效的速记。我错误地认为每个人都会知道这一点。很抱歉。为了更清楚,我正在尝试从SELECT语句中删除IIF(与大小写相同)。我不明白为什么