[数据处理] select中如何使用参数

Silvia铂金二 显示全部楼层 发表于 2022-10-27 10:49:07 |阅读模式 打印 上一主题 下一主题
1
已解决

【数据处理】 select中如何使用参数

  • 永洪vip Silvia铂金二
  • 2022-10-27 10:49:07
  • 发布在 论坛
2376 11
要在case when 中使用p_sort如何使用
select *,case  when <p_sort> ?{p_sort} = 'Amount(ThisPeriod).Asc'</p_sort> then TaxAmountRMBTP
when <p_sort> ?{p_sort} = 'Amount(ThisPeriod).Desc' </p_sort> then TaxAmountRMBTP * (-1)
when <p_sort> ?{p_sort} = 'QtyComp.Asc'</p_sort> then QTYComp
else QTYComp * (-1)
end as SortCol
from T

最佳答案

永洪社区YVP
阿姆斯特朗炮 皇冠三 关注Ta

2022-10-27 10:49:08

case when ?{p_sort} = 'Amount(ThisPeriod).Asc' then TaxAmountRMBTP when ?{p_sort}= 'Amount(ThisPeriod).Desc' then TaxAmountRMBTP * (-1) when ?{p_sort} = 'QtyComp.Asc' then QTYComp WHEN 1 = 1 THEN QTYComp * (-1) end as SortCol这样再试试
查看完整内容
回复

使用道具 举报

精彩评论11

阿姆斯特朗炮皇冠三 显示全部楼层 发表于 2022-10-27 10:49:08
瓜娃子 发表于 2022-10-27 14:08
不行,报错:不能单独使用带尖括号的参数,使用格式必须是 ?{p}

case   
<p_sort> when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMBTP
when ?{p_sort}=  'Amount(ThisPeriod).Desc'  then TaxAmountRMBTP * (-1)
when ?{p_sort} = 'QtyComp.Asc'  then QTYComp </p_sort>
WHEN 1 = 1 THEN QTYComp * (-1)
end as SortCol这样再试试
回复

使用道具 举报

yhdata_lyaa 显示全部楼层 发表于 2022-10-27 11:31:01
回复

使用道具 举报

Silvia铂金二 显示全部楼层 发表于 2022-10-27 13:10:23
yhdata_lyaa 发表于 2022-10-27 11:31
参考https://www.yonghongtech.com/help/Z-Suite/10.0/ch/paramindataset.html

p_sort没有传值要怎么处理
回复

使用道具 举报

yhdata_lyaa 显示全部楼层 发表于 2022-10-27 13:19:26
瓜娃子 发表于 2022-10-27 13:10
p_sort没有传值要怎么处理

例如<a>where city=?{a}</a>,参数可以不传值
回复

使用道具 举报

阿姆斯特朗炮皇冠三 显示全部楼层 发表于 2022-10-27 13:27:34
瓜娃子 发表于 2022-10-27 13:10
p_sort没有传值要怎么处理

<p_sort> ?{p_sort} = 'Amount(ThisPeriod).Asc'</p_sort>两个尖括号<></>之前的语句,如果有参数,会把参数替换?{p_sort}替换为你传过来的值,如果没有传参数,那么<></>这两个括号包括中间的语句就相当于没有,也就是<p_sort> ?{p_sort} = 'Amount(ThisPeriod).Asc'</p_sort>这一句话相当于没有写,这样说能明白吗
回复

使用道具 举报

Silvia铂金二 显示全部楼层 发表于 2022-10-27 13:29:39
阿姆斯特朗炮 发表于 2022-10-27 13:27
?{p_sort} = 'Amount(ThisPeriod).Asc'两个尖括号之前的语句,如果有参数,会把参数替换?{p_sort}替换为 ...

不太明白,我这样写的要怎么改
case   
when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMBTP
when ?{p_sort}=  'Amount(ThisPeriod).Desc'  then TaxAmountRMBTP * (-1)
when ?{p_sort} = 'QtyComp.Asc'  then QTYComp
else QTYComp * (-1)
end as SortCol
回复

使用道具 举报

阿姆斯特朗炮皇冠三 显示全部楼层 发表于 2022-10-27 13:39:11
瓜娃子 发表于 2022-10-27 13:29
不太明白,我这样写的要怎么改
case   
when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMB ...

你的参数肯定会传过去还是说参数有可能是空的?
回复

使用道具 举报

Silvia铂金二 显示全部楼层 发表于 2022-10-27 13:46:39
阿姆斯特朗炮 发表于 2022-10-27 13:39
你的参数肯定会传过去还是说参数有可能是空的?

参数为空啊,在select里面,就看我写的那个语句
回复

使用道具 举报

阿姆斯特朗炮皇冠三 显示全部楼层 发表于 2022-10-27 13:47:35
瓜娃子 发表于 2022-10-27 13:46
参数为空啊,在select里面,就看我写的那个语句

<p_sort> case   
when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMBTP
when ?{p_sort}=  'Amount(ThisPeriod).Desc'  then TaxAmountRMBTP * (-1)
when ?{p_sort} = 'QtyComp.Asc'  then QTYComp
ELSE </p_sort> QTYComp * (-1)
<p_sort> END </p_sort> as SortCol你这样试试
回复

使用道具 举报

高级模式
您需要登录后才可以回帖 登录 | 免费注册

  • 官方微信

    欢迎关注永洪服务号!收费为0,价值无限

    扫码关注
  • 新浪微博

    让每位用户轻松挖掘数据价值!

    访问新浪微博
  • 智能客服
50W

会员等你来哦

Copyright   ©2012-2024  北京永洪商智科技有限公司  (京ICP备12050607) 京公网安备110110802011451号 |联系社区管理员|《永洪社区协议》
返回顶部