想在SQL语句里面用公式控制字段的显示与隐藏

SELECT 

co.client

${IF(LEN(wtd) == 0,""," ,CASE WHEN a.WorkSheetTypeDisplay = '搬运' THEN IIF((a.WorkSheetType & 761907)> 0,IIF(a.RealWeight>=ISNULL(a.RealKGS,0),a.RealWeight,ISNULL(a.RealKGS,0)),0) ELSE 0 END AS weight")}

FROM dbo.DWD_ORDERS a

JOIN (

SELECT 

WorkSheetCode,

IIF(yuanshi IS NULL ,IIF(yincang IS NULL,ClientForShort,yincang),yuanshi ) AS client

FROM dbo.ClientRealOrNot 

) co  ON a.WorkSheetCode = co.WorkSheetCode

求问,如上述语句所示,我想当 wtd 这个参数为搬运的时候展示client和weight 这个字段,wtd 为推运的时候展示client和height这个字段,需要怎么写

FineReport 唐流雨 发布于 2023-2-27 15:02 (编辑于 2023-2-27 15:03)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
用户k6280494Lv6资深互助
发布于2023-2-27 15:07(编辑于 2023-2-27 15:07)

SELECT 

co.client

${if(wtd='搬运',"weight",if(wtd='推运',"height","") )}

FROM dbo.DWD_ORDERS a

JOIN (

SELECT 

WorkSheetCode,

IIF(yuanshi IS NULL ,IIF(yincang IS NULL,ClientForShort,yincang),yuanshi ) AS client

FROM dbo.ClientRealOrNot 

) co  ON a.WorkSheetCode = co.WorkSheetCode

最佳回答
0
程疏影Lv4见习互助
发布于2023-2-27 15:47(编辑于 2023-2-27 15:48)

select co.client

, ${switch(wtd,'搬运','weight','推运','height')} as col1

from dbo.dwd_orders a

     join (

  select worksheetcode

       , iif(yuanshi is null, iif(yincang is null, clientforshort, yincang), yuanshi) as client

  from dbo.clientrealornot

) co on a.worksheetcode = co.worksheetcode

  • 3关注人数
  • 261浏览人数
  • 最后回答于:2023-2-27 15:48
    请选择关闭问题的原因
    确定 取消
    返回顶部