开发者

case statement issues in sql

开发者 https://www.devze.com 2023-04-12 02:56 出处:网络
I am writing a small case statement in sql query as follows: SELECT [##OT_NET_EQUATIONS_RHS_IDS].SYS_ID,

I am writing a small case statement in sql query as follows:

 SELECT [##OT_NET_EQUATIONS_RHS_IDS].SYS_ID,
        [##OT_NET_EQUATIONS_RHS_IDS].NODE_ID,
        [##OT_NET_EQUATIONS_RHS_IDS].NODE_EQ_NO, 
        [##OT_NET_EQUATIONS_RHS_IDS].EQ_TYPE,
        CASE EQ_TP_OFFSET
          WHEN 'MULTIPLE' THEN '1'
          WHEN 'SINGLE' THEN '0'
        END AS EQ_TP_OFFSET,
        [##OT_NET_EQUATIONS_RHS_IDS].VAR_NAME,
        [##OT_NET_EQUATIONS_RHS_IDS].VAR_SET,
        [##OT_NET_EQUATIONS_RHS_IDS].VAR_SUBSET, 
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_NODE_ID, 
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_NODE_VAR_ID,
        CASE RHS_RELN
          WHEN 'EQ' THEN '0'
          WHEN 'LE' THEN '1'
          WHEN 'GE' THEN '2'
          WHEN 'MIN' THEN '3'
          WHEN 'MAX' THEN '4'
        END AS RHS_RELN,
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_OBJECT,
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_VAR_TYPE,
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_TP_OFFSET,
        [##OT_NET_EQUATIONS_RHS_IDS].TIME_PRD,
        [##OT_NET_EQUATIONS_RHS_IDS].RHS_VALUE,  
   开发者_运维知识库     [##OT_NET_EQUATIONS_RHS_IDS].SUB_NET_ID, 
        CASE RHS_OBJECT
          WHEN 'OBJECTIVE' THEN 'OBJECTIVE'
        END AS FUNC_NAME 
   FROM ##OT_NET_EQUATIONS_RHS_IDS;

I am getting error cannot convert varchar value 'multiple' to data type int...any help.? i am not sure why i am getting this error though i have put one ''.


I'm guessing EQ_TP_OFFSET is an int, so when Sql Server is evaluating the CASE, it tries to compare 'MULTIPLE' to the value of EQ_TP_OFFSET and cannot convert it to an int.

Looking at it again, I'm thinking perhaps EQ_TP_OFFSET is an int and you meant to code the case to select a value more meaningful than 1 and 0. Perhaps it should be the other way around?

CASE EQ_TP_OFFSET 
    WHEN 1 THEN 'MULTIPLE'  
    WHEN 0 THEN 'SINGLE' 
END AS EQ_TP_OFFSET

Same would go for RHS_RELN.

0

精彩评论

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

关注公众号