Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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 server T-SQL中的SQL Server CASE语句_Sql Server_Case - Fatal编程技术网

Sql server T-SQL中的SQL Server CASE语句

Sql server T-SQL中的SQL Server CASE语句,sql-server,case,Sql Server,Case,嗨,我正在处理涉及用例的查询。我不断地出错,不知道为什么。下面是我试过的 SELECT CASE when LineItem like '%Apple%' THEN ProductType = 'Apple' when LineItem like '%Orange' THEN ProductType = 'Orange' when LineItem like '%Strawberry' THEN ProductType = 'Red' whe

嗨,我正在处理涉及用例的查询。我不断地出错,不知道为什么。下面是我试过的

SELECT 

   CASE 

     when LineItem like '%Apple%' THEN ProductType = 'Apple'
     when LineItem like '%Orange' THEN ProductType = 'Orange'
     when LineItem like '%Strawberry' THEN ProductType = 'Red'
     when ProductType like 'Yellow' THEN ProductType
     else ProductType = 'White'

   end as ProductType

FROM Fruits
我得到的错误在=符号上。
在T-SQL中,WHEN关键字后面不可能有两个不同的列吗?

只是语法错误。不需要那么ProductType=“…”

像这样试试

SELECT 
    ProductType = CASE 
                        WHEN f.LineItem like '%Apple%' THEN 'Apple'
                        WHEN f.LineItem like '%Orange' THEN 'Orange'
                        WHEN f.LineItem like '%Strawberry' THEN 'Red'
                        WHEN f.ProductType like 'Yellow' THEN f.ProductType
                        ELSE 'White'
                    END
FROM 
    dbo.Fruits f;
去掉ProductType=。只需使用其他“白色”,记住像“黄色”这样的ProductType充当=
SELECT 
    ProductType = CASE 
                        WHEN f.LineItem like '%Apple%' THEN 'Apple'
                        WHEN f.LineItem like '%Orange' THEN 'Orange'
                        WHEN f.LineItem like '%Strawberry' THEN 'Red'
                        WHEN f.ProductType like 'Yellow' THEN f.ProductType
                        ELSE 'White'
                    END
FROM 
    dbo.Fruits f;