永洪社区

标题: select中如何使用参数 [打印本页]

作者: Silvia    时间: 2022-10-27 10:49
标题: select中如何使用参数
要在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


作者: 阿姆斯特朗炮    时间: 2022-10-27 10:49
瓜娃子 发表于 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
参考https://www.yonghongtech.com/hel ... paramindataset.html
作者: Silvia    时间: 2022-10-27 13:10
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
瓜娃子 发表于 2022-10-27 13:10
p_sort没有传值要怎么处理

例如<a>where city=?{a}</a>,参数可以不传值
作者: 阿姆斯特朗炮    时间: 2022-10-27 13:27
瓜娃子 发表于 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
阿姆斯特朗炮 发表于 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
瓜娃子 发表于 2022-10-27 13:29
不太明白,我这样写的要怎么改
case   
when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMB ...

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

作者: Silvia    时间: 2022-10-27 13:46
阿姆斯特朗炮 发表于 2022-10-27 13:39
你的参数肯定会传过去还是说参数有可能是空的?

参数为空啊,在select里面,就看我写的那个语句
作者: 阿姆斯特朗炮    时间: 2022-10-27 13:47
瓜娃子 发表于 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你这样试试
作者: Silvia    时间: 2022-10-27 14:08
阿姆斯特朗炮 发表于 2022-10-27 13:47
case   
when ?{p_sort} = 'Amount(ThisPeriod).Asc'  then TaxAmountRMBTP
when ?{p_sort}=  'Amount(T ...

不行,报错:不能单独使用带尖括号的参数,使用格式必须是<p> ?{p} </p>
作者: Silvia    时间: 2022-10-27 14:09
yhdata_lyaa 发表于 2022-10-27 13:19
例如where city=?{a},参数可以不传值

我是用在select里的




欢迎光临 永洪社区 (http://club.yonghongtech.com/) Powered by Discuz! X3.4