以下代码的描述?

时间:2015-07-14 09:38:02

标签: sql postgresql

我确实有一种情况,即开发存储过程的程序员不在,并且不再工作,所以我必须对代码进行一些更新。我应该在代码中添加另外两个变量,我知道这个地方,但我不知道如何把它...你能描述下面的代码,它在sql方面做了什么?因为我知道这个代码在程序中的含义..

RAISE NOTICE 'STAT CARD: formid=%',formid; 
    DROP TABLE IF EXISTS tbl_aggregation; 
--  execute 
    sql_ := 'CREATE TEMPORARY TABLE tbl_aggregation as ' --select programstageinstanceid,'|| dynamic_columns ||' from patientdatavalue'
        ||'
        select OrgUnitID
            , max(dateperiod) as dateperiod
            , programstageinstanceid
            , max("[DE:202062.202063.575]"::integer) as "[DE:202062.202063.575]"    
            , max(
                (case when position(''-'' in "[DE:202062.202063.202095]")>0 then substring("[DE:202062.202063.202095]" from 0 for position(''-'' in "[DE:202062.202063.202095]"))
                 else "[DE:202062.202063.202095]" end)
                 ) as "[DE:202062.202063.202095]" 
            , sum("[DE:202062.202063.202078]"::integer) as "[DE:202062.202063.202078]" 
            , max("[DE:202062.202063.202076]") as "[DE:202062.202063.202076]" 

        from 
        (
            select psi.organisationunitid as OrgUnitID
            , ou.name as OrgName, pdv.timestamp as DatePeriod
            , pdv.programstageinstanceid
            , pdv.dataelementid
            , pdv.value,'
            || dynamic_columns ||'          
            from patientdatavalue pdv inner join programstageinstance psi 
            on pdv.programstageinstanceid = psi.programstageinstanceid 
        --   left join organisationunit ou 
            inner join tbl_org_list ou 
            on psi.organisationunitid = ou.organisationunitid 

            where psi.completed=''t'' and 
            psi.duedate >= '''||period_from ||''' and 
            psi.duedate <= '''||period_to ||'''
        )as aggregation_
        '||cCondition||'
        group by programstageinstanceid, OrgUnitID 
        ';

在此代码中,存在硬编码的变量&#34;如[DE:202062.202063.575][DE:202062.202063.202078]等。我还有两个不同的[DE:xxx,xxx,xx]我应该在这里添加。

因为无论何时我运行这个存储过程它都不起作用并且给出了那些新的[DE:xxx,xxx,xx]不存在的错误。所以我应该让它们存在于代码中,但是在哪里把它们?要做到这一点,我必须了解sql语法及其功能,不幸的是我在sql中使用了noob。

0 个答案:

没有答案