使用codeigniter执行存储过程

时间:2015-11-08 20:03:23

标签: php codeigniter tsql

我尝试使用codeignter执行我的sproc,但我收到此错误。CodeIgniter Error

这就是我通过codeigniter $this->db->query("SP_COUNT_IRA 'ROGER', 'GLOBE' ");

调用我的sp的方式

下面是我的杂志。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_COUNT_IRA] (@USERNAME VARCHAR(30) , @PROG_ID VARCHAR(30) )      
AS    
BEGIN  
 DECLARE @COUNT_IRA INT
 DECLARE @IRA INT 
 DECLARE @COUNT INT
 DECLARE @VARIANCE INT 
 DECLARE @CC INT
 DECLARE @SS INT
 DECLARE @WW INT

    SELECT @COUNT = 3
    SELECT @VARIANCE = 2
            /*(convert(decimal(16,1),
                                ((SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT))
                        ))
                FROM SCH_CYCLECOUNT*/

    IF @COUNT > @VARIANCE 
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 - (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount)) end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )
        PRINT '1'
        END
    ELSE IF @VARIANCE > @COUNT 
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 + (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount))end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )
        PRINT '2'
        END
    ELSE IF @VARIANCE = 0 OR @VARIANCE = @COUNT
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 * (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount))end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )
        PRINT '3'
        END 

        SET @CC = ( select distinct IRA = (100 - ( 
            CASE 
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Cycle Count') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand') - 
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Cycle Count')  * 1.0) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand') * 1.0)end)*100
             when 0 then 100 end))
            from sch_cyclecount )
        SET @SS = ( select distinct IRA = (100- (
            CASE 
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') -
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') ) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') * 1.0)end ) * 100
            when 0 then 100 end))
            from sch_cyclecount )
        SET @WW = ( select distinct IRA = (100- (
            CASE
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') -
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') ) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') * 1.0)end ) * 100
            when 0 then 100 end))
            from sch_cyclecount )



    UPDATE SCH_CYCLECOUNT_IRA SET PROG_ID = @PROG_ID, IRA = @IRA, CC_AC = @CC, CC_WW = @WW, CC_SS = @SS WHERE PROG_ID = @PROG_ID
END 

我使用sqlsrv作为我的config.php中定义的dbdriver。

1 个答案:

答案 0 :(得分:0)

我已经通过删除所有PRINT解决了这个问题,谢谢。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_COUNT_IRA] (@USERNAME VARCHAR(30) , @PROG_ID VARCHAR(30) )      
AS    
BEGIN  
 DECLARE @COUNT_IRA INT
 DECLARE @IRA INT 
 DECLARE @COUNT INT
 DECLARE @VARIANCE INT 
 DECLARE @CC INT
 DECLARE @SS INT
 DECLARE @WW INT

    SELECT @COUNT = 3
    SELECT @VARIANCE = 2
            /*(convert(decimal(16,1),
                                ((SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT))
                        ))
                FROM SCH_CYCLECOUNT*/

    IF @COUNT > @VARIANCE 
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 - (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount)) end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )

        END
    ELSE IF @VARIANCE > @COUNT 
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 + (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount))end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )

        END
    ELSE IF @VARIANCE = 0 OR @VARIANCE = @COUNT
        BEGIN
            SET @IRA = (select distinct IRA = (convert(decimal(16,1), case (select distinct count(sku) from sch_variance_report a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger' ) when 0 then 0.0 else
                        1 * (convert(decimal(16,1),(SELECT DISTINCT count(sku) from sch_cyclecount) - (SELECT DISTINCT count(sku) from SCH_VARIANCE_REPORT)) 
                        /(select distinct count(sku) from sch_cyclecount))end) * 100) 
                        from sch_variance_report a inner join sch_cyclecount b on a.sku = b.sku and 
                        a.ref_no = b.ref_no and a.prog_id = b.prog_id inner join sch_web_users_detail c on a.prog_id = c.prog_id where c.user_id = 'roger' )

        END 

        SET @CC = ( select distinct IRA = (100 - ( 
            CASE 
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Cycle Count') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand') - 
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Cycle Count')  * 1.0) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand') * 1.0)end)*100
             when 0 then 100 end))
            from sch_cyclecount )
        SET @SS = ( select distinct IRA = (100- (
            CASE 
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') -
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') ) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id 
            where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') * 1.0)end ) * 100
            when 0 then 100 end))
            from sch_cyclecount )
        SET @WW = ( select distinct IRA = (100- (
            CASE
            (case (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') when 0 then 0.0 else 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') -
            (select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'System to System') ) / 
            ((select distinct count(sku)from sch_cyclecount a inner join sch_web_users_detail b on a.prog_id = b.prog_id where b.user_id = 'roger'and count_type = 'Stock on Hand(S2S)') * 1.0)end ) * 100
            when 0 then 100 end))
            from sch_cyclecount )



    UPDATE SCH_CYCLECOUNT_IRA SET PROG_ID = @PROG_ID, IRA = @IRA, CC_AC = @CC, CC_WW = @WW, CC_SS = @SS WHERE PROG_ID = @PROG_ID
END 
相关问题