写一个SQR条件语句

时间:2014-03-09 16:31:51

标签: sqr

我是SQR的新手。我需要帮助来编写变量并将其用于条件语句。我的伪代码

declare $head_print

let $head_print = (select * from PS_DTR_RPT_ACCT
where RPT_TREE_NODE = 'REAL_ESTATE_EXP' 
or TREE_NODE_NUM between 4600000 and 4699999)

if(head_print contain REAL_ESTATE_EXP or Account between 46000000 and 4699999)
then head_print = "REAL ESTATE";
else head_print = "Capital ESTATE";

1 个答案:

答案 0 :(得分:1)

不太清楚你想要什么,所以我做了一个假设。 看来如果某个值在表PS_DTR_RPT_ACCT中,那么你想要它说'#34; REAL ESTATE"否则说" CAPITAL ESTATE"

现在使用SQR,你必须把你的SQL放在一个开始选择块中 - 规则非常严格 - 字段名必须在第1列 - 第1列中的NOT下面的代码。在下面的例程中,我是试图在真实的SQR中编写你的伪代码,但是,我无法测试它,所以你可能会收到错误 - 而且我不知道你的字段名称,因为它只是说"选择*"。 / p>

Begin-Report

   do GetData

End-Report

Begin-Procedure GetData

! Initialize value - if no data found, query this later and set it to the "ELSE"
Let $Head_print = ''

Begin-Select

Head_Print
   ! Override the value from the table but only if you need to
   Let $Head_Print = 'REAL ESTATE'

from PS_DTR_RPT_ACCT
Where RPT_TREE_NODE = 'REAL_ESTATE_EXP' 
or TREE_NODE_NUM between 4600000 and 4699999)

End-Select 

! If $Head_print is blank, then no value was found with the sql - do the ELSE part
If $Head_Print = ''
   Let $Head_Print = 'Capital Estate'
End-If

End-Procedure

SQR是一种非常好的有限语言学习 - 语法有点严格,但与SQL基本一样简单。我建议阅读参考手册 - 它可以从Oracle下载。

随意询问有关SQR的任何其他问题 - 如果您这样做,我会收到警报 - 抱歉这需要很长时间才能回答