简体   繁体   English

在PHP中求和两个Pervsive SQL语句

[英]Sum Two Pervsive SQL statements in PHP

I am running a script that does MANY things but I am trying to get a Pervasive statement to work in my php that works in the DB that I am querying. 我正在运行执行许多操作的脚本,但是我试图使Pervasive语句在我正在查询的数据库中工作的php中工作。 I have tried all my tricks, but have had no success with getting this to work in the table that this is supposed to be displayed in. 我已经尝试了所有技巧,但在将其显示在应该显示的表中时没有成功。

$pom = $dbx->getOne('SELECT (SELECT SUM(wrt_sls) FROM wrt 
        WHERE wrt_cat = \'POM\' 
        AND wrt_cng_dat_4 >= '.$start.' 
        AND wrt_cng_dat_4 <= '.$end.' 
        AND wrt_pft_ctr in '.$pcs.') +
        (SELECT SUM(wrt_sls) FROM wrt 
        WHERE wrt_cat in (\'BED\',\'MP\')
        AND wrt_vend_id = \'PROTECTABED\' 
        AND wrt_cng_dat_4 >= '.$start.' 
        AND wrt_cng_dat_4 <= '.$end.' 
        AND wrt_pft_ctr in '.$pcs);

Again, I get the right result in Pervasive but am getting nothing in the actual application. 同样,我在Pervasive中得到了正确的结果,但在实际应用程序中却什么也没得到。 Any tips? 有小费吗?

The first thing I would check is the values of $start, $end, and $pcs. 我要检查的第一件事是$ start,$ end和$ pcs的值。 For example, the way you are using them they appear to be INT values. 例如,使用它们的方式它们似乎是INT值。 However, if the columns in the table are not of type INT, then they are not quoted correctly in your query. 但是,如果表中的列不是INT类型,则在查询中不会正确引用它们。 I also do not see the ending ) that will be required in your query to work correctly. 我也看不到查询的结尾(),才能正常工作。 You may need to rewrite your query like: 您可能需要像下面这样重写查询:

$pom = $dbx->getOne("SELECT (SELECT SUM(wrt_sls) FROM wrt 
        WHERE wrt_cat = 'POM' 
        AND wrt_cng_dat_4 >= '" . $start . "' 
        AND wrt_cng_dat_4 <= '" . $end . "' 
        AND wrt_pft_ctr in '" . $pcs . "') +
        (SELECT SUM(wrt_sls) FROM wrt 
        WHERE wrt_cat in ('BED','MP')
        AND wrt_vend_id = 'PROTECTABED' 
        AND wrt_cng_dat_4 >= '" . $start . "' 
        AND wrt_cng_dat_4 <= '" . $end . "' 
        AND wrt_pft_ctr in '" . $pcs ."')");

Nope that doesn't seem to work either, but I took different approach and this is what ended up working ... 不,这似乎也不起作用,但是我采用了不同的方法,这才最终起作用了……

$pom = $dbx->getOne('
    SELECT SUM(wrt_sls) FROM wrt 
        WHERE wrt_cat = \'POM\' 
        AND wrt_cng_dat_4 >= '.$start.' 
        AND wrt_cng_dat_4 <= '.$end.' 
        AND wrt_pft_ctr in '.$pcs);

$pab = $dbx->getOne('
    SELECT SUM(wrt_sls) FROM wrt 
        WHERE  wrt_cat = \'BED\'
        AND wrt_vend_id = \'PROTECTABED\' 
        AND wrt_cng_dat_4 >= '.$start.' 
        AND wrt_cng_dat_4 <= '.$end.' 
        AND wrt_pft_ctr in '.$pcs);

$protect = $pom + $pab;

$tpom += $protect;

Thanks a lot for the reply. 非常感谢您的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM