开发者

Syntax error on create query.Please guide

开发者 https://www.devze.com 2023-04-02 20:40 出处:网络
CREATE TABLE Report AS (SELECT b.Id, (CASE WHEN b.Svc_Id = 3 THEN \'NET MARKET\' WHEN b.Svc_Id = 8 THEN \'NET SAL\'
CREATE TABLE Report AS 
 (SELECT b.Id, 
  (CASE WHEN b.Svc_Id = 3 THEN 'NET MARKET'
        WHEN b.Svc_Id = 8 THEN 'NET SAL'
        WHEN b.Svc_Id = 7 THEN 'NET RESAT'
        WHEN b.Svc_Id = 20 THEN 'NET TAX'
  END) as CurrSvcId,
  b.Classification,
  (CASE WHEN a.NewSvcId = 6 THEN 'Priority Low'
        WHEN a.NewSvcId = 9 THEN 'Priority Medium'
        WHEN a.NewSvcId = 21 THEN 'Priority High'
  END) as SINewSvcCd,
  b.Login_Name
  FROM Market_Data b, Report a
  WHERE ((b.Svc_Id = 3 and a.NewSvcId = 0) OR (b.Svc_Id = 3 AND a.NewSvcId > 0 ))
  开发者_StackOverflow中文版  AND a.Flag = 0 AND b.User_Id = a.User_Id
    AND a.Status = 'ACTIVE'
    AND a.RetCode = 0 order by b.SvcId
 )

I get a error stating missing right paranthesis. Please help me on this


CREATE TABLE Report AS 
   SELECT b.Id, 
        ( CASE b.Svc_Id
             WHEN 3 
             THEN 'NET MARKET' 
             WHEN 8 
             THEN 'NET SAL' 
             WHEN 7 
             THEN 'NET RESAT' 
             WHEN 20 
             THEN 'NET TAX' 
           END ) as CurrSvcId, 
        b.Classification, 
        ( CASE a.NewSvcId
             WHEN 6 
             THEN 'Priority Low' 
             WHEN 9 
             THEN 'Priority Medium' 
             WHEN 21 
             THEN 'Priority High' 
           END ) as SINewSvcCd, 
        b.Login_Name 
   FROM Market_Data b, 
        Report a 
  WHERE (b.Svc_Id = 3 AND a.NewSvcId >= 0 )
    AND a.Flag = 0 
    AND b.User_Id = a.User_Id 
    AND a.Status = 'ACTIVE' 
    AND a.RetCode = 0 
  order by b.SvcId;

You should add an "ELSE" section to both of your "CASE" statements to trap any other values that might occur (however unlikely).

The "ORDER BY" clause might be spurious, do you really need the rows entered into a RDBMS table in a specific order? You might but generally you won't, consider whether you need it or not.

You might also want to consider a storage clause etc. if you are unsure, speak to your DBA about it.

Hope it helps

0

精彩评论

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