开发者

How to control string space in SQL Server?

开发者 https://www.devze.com 2023-02-18 18:05 出处:网络
I change this开发者_如何学C : SELECT FLAG, DESCRIPTION FROM MYTABLE AS A WHERE ((A.FLAG = 0 AND A.DESCRIPTION IS NULL)

I change this开发者_如何学C :

SELECT 
   FLAG, DESCRIPTION 
FROM MYTABLE AS A
WHERE
   ((A.FLAG = 0 AND A.DESCRIPTION IS NULL) 
    OR (A.FLAG != 0 AND A.DESCRIPTION IS NULL))

with this :

SELECT 
    FLAG, DESCRIPTION 
FROM MYTABLE  AS A
WHERE 
   ((A.FLAG = 0 AND 
      CASE LTRIM(RTRIM(A.DESCRIPTION)) 
         WHEN ‘’ THEN NULL 
         ELSE A.DESCRIPTION 
      END IS NULL) 
     OR 
     (A.FLAG != 0 AND 
         CASE LTRIM(RTRIM(A.DESCRIPTION))
            WHEN ‘’ THEN NULL 
            ELSE A.DESCRIPTION  
         END IS NULL)
     )

but it gives error about 'case when'. How to solve this? thanks in advance.


You have two CASE and only one corresponding END. Each of the CASE should be closed by it's own END.

EDIT: You updated the query in question. You new query is fine, it executes here with no problem. If it gives error on your end, then there is something else you are not telling us in the problem description.

How to control string space in SQL Server?

0

精彩评论

暂无评论...
验证码 换一张
取 消