Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:53:25+00:00 2026-06-04T05:53:25+00:00

I am trying to insert some data. It is not getting inserted in the

  • 0

I am trying to insert some data. It is not getting inserted in the table using transactions. Instead, it is going to the catch block. Below is sql stored procedure:
GO

/****** Object:  StoredProcedure [dbo].[rml_re_GetAndStoreConsumerSubscriptionData_NEWUPS] Script Date: 05/21/2012 12:39:59 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

--EXEC rml_re_GetAndStoreConsumerSubscriptionData_NEWUPS
ALTER PROCEDURE [dbo].[rml_re_GetAndStoreConsumerSubscriptionData_NEWUPS]  

AS
BEGIN  
 DECLARE @currenttime datetime  
 SET @currenttime= getdate()  
 INSERT INTO rml_re_consumerdatasync_log VALUES('rml_re_GetAndStoreConsumerSubscriptionData',@currenttime,null,'started',@currenttime,'',getdate(),null);  
  BEGIN TRY  
    BEGIN TRANSACTION PULLCONSUMERDATA  
        DECLARE @dbServerName VARCHAR(50),@databaseName VARCHAR(50),@dbUserName VARCHAR(50),@query VARCHAR(MAX)    
        SELECT  @dbServerName=dbservername,@databaseName=dbname,@dbUserName=dbusername FROM rml_re_applications   
        WHERE id=(SELECT configvalue FROM rml_re_configuration WHERE configname='CRMApplicationID')

        -- Removes all old data before insertion.  
        ALTER TABLE [dbo].[rml_re_consumermarkets] DROP CONSTRAINT [FK_rml_re_consumermarkets_rml_re_consumercrops]
        ALTER TABLE [dbo].[rml_re_consumermarkets] DROP CONSTRAINT [FK_rml_re_ConsumerSubscriptionMarket_rml_re_ConsumerSubscriptionData]
        ALTER TABLE [dbo].[rml_re_consumercrops] DROP CONSTRAINT [FK_rml_re_ConsumerSubscriptionCrops_rml_re_ConsumerSubscriptionData]

        TRUNCATE TABLE rml_re_consumermarkets
        TRUNCATE TABLE rml_re_consumercrops
        TRUNCATE TABLE rml_re_ConsumerSubscriptionData

    ALTER TABLE [dbo].[rml_re_consumercrops]  WITH NOCHECK ADD  CONSTRAINT [FK_rml_re_ConsumerSubscriptionCrops_rml_re_ConsumerSubscriptionData] FOREIGN KEY([subscriptionid])
    REFERENCES [dbo].[rml_re_ConsumerSubscriptionData] ([id])
    ALTER TABLE [dbo].[rml_re_consumermarkets]  WITH NOCHECK ADD  CONSTRAINT [FK_rml_re_ConsumerSubscriptionMarket_rml_re_ConsumerSubscriptionData] FOREIGN KEY([subscriptionid])
    REFERENCES [dbo].[rml_re_ConsumerSubscriptionData] ([id])
    ALTER TABLE [dbo].[rml_re_consumermarkets]  WITH CHECK ADD  CONSTRAINT [FK_rml_re_consumermarkets_rml_re_consumercrops] FOREIGN KEY([cropid])
    REFERENCES [dbo].[rml_re_consumercrops] ([cropid])


        SET @query='';
        SET @query= 'INSERT INTO rml_re_ConsumerSubscriptionData(id,msisdn,consumername,
                    languagetype,statecode,talukcode,districtcode,regioncode,status,
                    subscriptionstartdate,subscriptionenddate,DistributorCode,
                    package,soiltype,comp_category,AdditionalInfo) 
                            SELECT  id,msisdn,
                            case when Len(consumername) <=150 then consumername else null end  as consumername,
                            case when Len(languagetype) <=10 then languagetype else null end  as languagetype ,'  
        SET @query=@query+' case when Len(statecode) <=5 then statecode else null end  as statecode ,
                            case when Len(talukcode) <=10 then talukcode else null end  as talukcode  ,
                            case when Len(districtcode) <=10 then districtcode else null end  as districtcode,
                            case when Len(regioncode) <=10 then regioncode else null end  as regioncode ,
                            case when Len(status) <=50 then status else null end  as status ,
                            subscriptionstartdate ,'  
        SET @query=@query+' subscriptionenddate,
                            case when Len(DistributorCode) <=100 then DistributorCode else null end as DistributorCode ,
                            case when Len(package) <=50 then package else null end AS package ,
                            case when Len(soiltype) <=50 then soiltype else null end   as soiltype,'  
        SET @query=@query+' case when Len(comp_category) <=50 then comp_category  else null end  as comp_category  ,
                            case when Len(AdditionalInfo) <=100 then AdditionalInfo  else null end  as AdditionalInfo '  
        SET @query=@query+' FROM '  
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New '
        SET @query=@query+' WHERE crop1code is not null AND crop2code is not null '



        EXEC (@query)  
        SET @query='';
        -- INSERT FOR rml_re_consumercrops
        --INSER FOR PRIMARY CROP
        SET @query='INSERT INTO rml_re_consumercrops(subscriptionid,commoditycode,sowingdate,sowingweek)'
        SET @query=@query+'SELECT id,case when Len(crop1code) <=15 then crop1code  else null end  as crop1code ,sowingdate1,DATEDIFF (WEEK,sowingdate1,getdate()) '
        SET @query=@query+' FROM '
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New '
        SET @query=@query+' WHERE crop1code is not null AND crop2code is not null'


        EXEC (@query)  
        SET @query=''
        --INSER FOR SECONDARY CROP
        SET @query='INSERT INTO rml_re_consumercrops(subscriptionid,commoditycode,sowingdate,sowingweek)'
        SET @query=@query+'SELECT id,case when Len(crop2code) <=15 then crop2code  else null end  as crop2code  ,sowingdate2,DATEDIFF (WEEK,sowingdate2,getdate()) '
        SET @query=@query+'FROM '
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New '
        SET @query=@query+' WHERE crop1code is not null AND crop2code is not null'

        EXEC (@query)  
        SET @query=''

        --INSERT FOR rml_re_consumermarkets
        --INSER FOR PRIMARY CROP
        SET @query='INSERT INTO rml_re_consumermarkets(cropid,subscriptionid,marketcode,ric)'
        SET @query=@query+'SELECT CS.cropid,E.id,case when Len(M.item) <=15 then M.item  else null end AS marketcode ,case when Len( R.item) <=15 then  R.item  else null end  AS ric '
        SET @query=@query+'FROM rml_re_consumercrops CS,'
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New  E ' 
        SET @query=@query+' OUTER APPLY fnSplit(E.Ric1,'+''','''+') R,'
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New  F '
        SET @query=@query+' OUTER APPLY fnSplit(F.MandiCode1,'+''','''+') M '
        SET @query=@query+' WHERE F.ID = E.ID 
                AND R.ID = M.ID
                AND CS.commoditycode = E.crop1code
                AND CS.subscriptionid=E.id 
                AND CS.subscriptionid=F.id '
        SET @query=@query+' AND E.crop1code is not null AND E.crop2code is not null'
        SET @query=@query+' AND F.crop1code is not null AND F.crop2code is not null'

        EXEC (@query)  
        SET @query=''
        --INSER FOR SECONDARY CROP
        SET @query='INSERT INTO rml_re_consumermarkets(cropid,subscriptionid,marketcode,ric) '
        SET @query=@query+'SELECT CS.cropid,E.id,case when Len(M.item) <=15 then M.item  else null end AS marketcode,case when Len( R.item) <=15 then R.item  else null end AS ric  '
        SET @query=@query+'FROM rml_re_consumercrops CS,'
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New  E '
        SET @query=@query+' OUTER APPLY fnSplit(E.Ric2,'+''','''+') R,'
        SET @query=@query+' ['+@dbServerName+'].'+@databaseName+'.'+@dbUserName+'.rml_re_getConsumerSubscriptionData_New  F ' 
        SET @query=@query+' OUTER APPLY fnSplit(F.MandiCode2,'+''','''+') M '
        SET @query=@query+' WHERE F.ID = E.ID 
              AND R.ID = M.ID
              AND CS.commoditycode = E.crop2code
              AND CS.subscriptionid=E.id 
              AND CS.subscriptionid=F.id '
        SET @query=@query+' AND E.crop1code is not null AND E.crop2code is not null'
        SET @query=@query+' AND F.crop1code is not null AND F.crop2code is not null'

    EXEC (@query)       
    COMMIT TRANSACTION PULLCONSUMERDATA  
    UPDATE  rml_re_consumerdatasync_log SET status='completed',endtime=getdate() WHERE logdate=@currenttime  
  END TRY  
  BEGIN CATCH  
  --  ROLLBACK TRANSACTION PULLCONSUMERDATA  

    UPDATE  rml_re_consumerdatasync_log SET status='failure',error_info=ERROR_MESSAGE() WHERE logdate=@currenttime  
  END CATCH  

END  

--exec rml_re_GetAndStoreConsumerSubscriptionData



GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:53:26+00:00Added an answer on June 4, 2026 at 5:53 am

    OK first here are somethings to do to help yourself. Add a debug parameter to the proc with a default of value of 0. Then add code to print the dynamic SQl rather than run it if you set the debuig parameter value to 1. This should be a standard practice anytime you use dynamic SQl in a proc. LIkely one of those dynamic statments is not forming correcly so you need to see teh generated SQL to find out what is wrong.

    You are storing the failure in the catch block, what error message are you getting?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert some text data into a table in SQL Server
I'm trying to insert some binary data into database using 'mysql' gem in ruby.
I'm trying to insert some data into a table with shell_exec (on localhost). Here's
I was trying to insert some data into a table and I got the
I am getting this error when trying to insert data into a data table
I'm getting error Not unique table/alias while trying to display data from MySQL database
I'm trying to insert some data into a table from a csv document which
I'm trying to insert some data into a database using an html form. The
I am trying to insert some data into one table and after that is
I'm trying to insert some data into a local MySQL database by using MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.