0

I'm trying to execute my sproc using codeignter but I'm getting this error.CodeIgniter Error

this is how I call my sp through codeigniter $this->db->query("SP_COUNT_IRA 'ROGER', 'GLOBE' ");

Below is my sproc.

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 

I'm using sqlsrv as dbdriver defined in my config.php.

1 Answer 1

0

I already solved this by removing all the PRINT, thanks.

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 

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.