Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在字符串中使用case语句_Sql_Sql Server - Fatal编程技术网

Sql 在字符串中使用case语句

Sql 在字符串中使用case语句,sql,sql-server,Sql,Sql Server,我需要把一个case语句放在一个字符串中。如何做到这一点 select DATEDIFF(MM, select CASE FA.new_ownertype WHEN 8 then FA.new_vlenrollmentstartdate ELSE FA.new_contractstartdate from BingMapsPlatform_Stagging.dbo.FilteredAccount as FA END, GETDATE()) sel

我需要把一个case语句放在一个字符串中。如何做到这一点

select DATEDIFF(MM, select CASE FA.new_ownertype
        WHEN 8 then FA.new_vlenrollmentstartdate
        ELSE FA.new_contractstartdate from BingMapsPlatform_Stagging.dbo.FilteredAccount as FA
        END, GETDATE())
select DATEDIFF(MM,
    CASE FA.new_ownertype
    WHEN 8 then FA.new_vlenrollmentstartdate
    ELSE FA.new_contractstartdate
    END, GETDATE())
from BingMapsPlatform_Stagging.dbo.FilteredAccount as FA