SQL 2000中的嵌套大小写

时间:2015-05-18 08:01:43

标签: sql sql-server case sql-server-2000

我有以下SQL语句,在SQL 2008上执行它时,它完美无缺。但是当在SQL 2000中被执行时它说:

  

内部SQL Server错误

我认为问题的出现是因为在SQL 2000中使用了嵌套的case语句。这是SQL语句:

 WHEN 14 THEN
                  Case When  (select COUNT(*) from [dbo].[mnrFnBI_Fixed](@CurrencyID) f where f.BAccCustID!=0x0 AND f.biMatID = bi.biMatID)>0 THEN

                    CASE  (select top 1 PriceType from  (select top 1 f.BDate,f.BNumber , tc.PriceType From [dbo].[mnrFnBI_Fixed](@CurrencyID) f  inner join #tcust tc on tc.AccID = f.BAccCustID AND tc.PriceType!=0 Where   f.biMatID =bi.biMatID AND f.BAccCustID != 0x0 order by f.BDate desc,f.BNumber  desc ) as k)  -- Price From customer Card 
                            WHEN 1 THEN 
                            CASE @UseUnit WHEN 1 THEN mtEndUser1 
                                    WHEN 2 THEN mtEndUser2  
                                    WHEN 3 THEN mtEndUser3  
                                    WHEN 4 THEN mtEndUser4  
                                    WHEN 5 THEN mtEndUser5  
                                    WHEN 0 THEN CASE [mtDefUnit]    WHEN 1 THEN mtEndUser1 
                                                    WHEN 2 THEN mtEndUser2  
                                                    WHEN 3 THEN mtEndUser3  
                                                    WHEN 4 THEN mtEndUser4  
                                                    WHEN 5 THEN mtEndUser5  
                                                END
                                    END
            ---*******************---
                            WHEN 2 THEN 
                            CASE @UseUnit WHEN 1 THEN  mtWhole1 
                                    WHEN 2 THEN mtWhole2 
                                    WHEN 3 THEN mtWhole3  
                                    WHEN 4 THEN mtWhole4  
                                    WHEN 5 THEN mtWhole5 
                                        WHEN 0 THEN CASE [mtDefUnit] WHEN 1 THEN mtWhole1 
                                                                WHEN 2 THEN mtWhole2  
                                                                WHEN 3 THEN mtWhole3 
                                                                WHEN 4 THEN mtWhole4  
                                                                WHEN 5 THEN mtWhole5 
                                                            END
                                        END 

                    ---*******************---           

                    END 
                    END

当我删除'*****'之间的部分时,它完美无缺!

请告诉我case语句如何与SQL 2000一起使用?!

更新 将上面的代码更改为:

 WHEN 14 THEN
                  Case  
                            WHEN (select COUNT(*) from [dbo].[mnrFnBI_Fixed](@CurrencyID) f where f.BAccCustID!=0x0 AND f.biMatID = bi.biMatID)>0 THEN

                case 
                when (select top 1 PriceType from  (select top 1 f.BDate,f.BNumber , tc.PriceType From [dbo].[mnrFnBI_Fixed](@CurrencyID) f  inner join #tcust tc on tc.AccID = f.BAccCustID AND tc.PriceType!=0 Where   f.biMatID =bi.biMatID AND f.BAccCustID != 0x0 order by f.BDate desc,f.BNumber  desc ) as k) =1 THEN 
                        CASE @UseUnit WHEN 1 THEN mtEndUser1 
                                WHEN 2 THEN mtEndUser2  
                                WHEN 3 THEN mtEndUser3  
                                WHEN 4 THEN mtEndUser4  
                                WHEN 5 THEN mtEndUser5  
                                WHEN 0 THEN CASE [mtDefUnit]    WHEN 1 THEN mtEndUser1 
                                                WHEN 2 THEN mtEndUser2  
                                                WHEN 3 THEN mtEndUser3  
                                                WHEN 4 THEN mtEndUser4  
                                                WHEN 5 THEN mtEndUser5  
                                            END
                                END


                when(select top 1 PriceType from  (select top 1 f.BDate,f.BNumber , tc.PriceType From [dbo].[mnrFnBI_Fixed](@CurrencyID) f  inner join #tcust tc on tc.AccID = f.BAccCustID AND tc.PriceType!=0 Where   f.biMatID =bi.biMatID AND f.BAccCustID != 0x0 order by f.BDate desc,f.BNumber  desc ) as k) = 2 THEN 
                        CASE @UseUnit WHEN 1 THEN  mtWhole1 
                                WHEN 2 THEN mtWhole2 
                                WHEN 3 THEN mtWhole3  
                                WHEN 4 THEN mtWhole4  
                                WHEN 5 THEN mtWhole5 
                                    WHEN 0 THEN CASE [mtDefUnit] WHEN 1 THEN mtWhole1 
                                                            WHEN 2 THEN mtWhole2  
                                                            WHEN 3 THEN mtWhole3 
                                                            WHEN 4 THEN mtWhole4  
                                                            WHEN 5 THEN mtWhole5 
                                                        END
                                    END 


                END 
                END

它有效,所以请告诉sql 2000中的第一个Sql命令有什么问题?!

1 个答案:

答案 0 :(得分:0)

此示例可以帮助您。

UPDATE table_name 
  SET column_name=CASE 
WHEN column_name in ('value1', 'value2',.....) 
  THEN 'update_value' 
WHEN column_name in ('value1', 'value2',.....) 
  THEN 'update_value' 
END