Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SQL cursor fetch problem

SQL cursor fetch problem

Scheduled Pinned Locked Moved C#
helpdatabase
15 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mmdullah

    I have tried it. returns same message mir

    J Offline
    J Offline
    jonhbt
    wrote on last edited by
    #5

    Be sure that the number of columns you are selecting in the select statement for the cursor is the same number of variables that you have when calling the Fetch

    M 1 Reply Last reply
    0
    • J jonhbt

      Be sure that the number of columns you are selecting in the select statement for the cursor is the same number of variables that you have when calling the Fetch

      M Offline
      M Offline
      mmdullah
      wrote on last edited by
      #6

      I have chacked it several times . Everything is fine . also the length for varchar types. the message not shown if I select into the first variable only. I don't know whats the problem with it . but I have wrote a lot of sp with such select into. :confused:

      J A 2 Replies Last reply
      0
      • M mmdullah

        problem arises when fetching cursors. please help asap. the function code: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE FUNCTION Get_Coll_Ovd_Report ( @fromDate datetime, @ToDate datetime, @dtOvdDate datetime, @dtOvdDatePrev datetime, @strAndPaid VARCHAR(300), @rdoFileInfoSpecific int, @SpecificFileNo varchar(20), @strAndFOfficer varchar(100), @strAndZone varchar(100), @strCollType varchar(50), @rdoStatusNID smallint, @rdoStatusBankOpen smallint, @chkOvdVal smallint, @rdoRepTypeAllDet smallint )Returns @retVal table( [SLNo] int, [TDate] DateTime, [GLRef] Varchar(50), [LdgAcNo] Varchar(50), [AcName] Varchar(200), [MRNo] int, [GLName] Varchar(200), [Cash] decimal(18,6), [Clear] decimal(18,6), [Trans] decimal(18,6), [CnTot] decimal(18,6), [FileNo] Varchar(50), [NidStat] smallint, [UserID] Varchar(50), [District] Varchar(50), [PaidAt] Varchar(50), [ZMrNo] Varchar(50), [ZMrDate] DateTime, [Model] Varchar(50), [FOID] int, [FClBal] decimal(18,6), [TotCol] decimal(18,6), [BLoan] decimal(18,6), [BTotDr] decimal(18,6), [OvdPrv] decimal(18,6), [P1] decimal(18,6), [P2] decimal(18,6)) AS BEGIN declare @f_SLNo int,@f_TDate datetime,@f_GLRef varchar(50), @f_LdgAcNo varchar(50) , @f_AcName varchar(200) , @f_MRNo int, @f_GLName varchar(50), @f_Cash decimal(18,6), @f_Clear decimal(18,6), @f_Trans decimal(18,6), @f_CnTot decimal(18,6), @f_FileNo varchar(30) , @f_NidStat smallint , @f_UserID varchar(50), @f_District varchar(50) , @f_PaidAt Varchar(50), @f_ZMrNo Varchar(50), @f_ZMrDate datetime, @f_Model Varchar(50) , @f_FOID int, @f_FClBal decimal(18,6), @f_TotCol decimal(18,6), @f_BLoan decimal(18,6), @f_BTotDr decimal(18,6), @f_OvdPrv decimal(18,6), @f_P1 decimal(18,6), @f_P2 decimal(18,6) declare @strSQL varchar(2000), @LdgAcNo varchar(12), @MAcName varchar(80), @FileNo varchar(30), @MaxiInstlAmt decimal(18,0), @MaxiMinInstlAmt decimal(18,0), @DCPDt datetime, @FClBal decimal(18,6), @Ac_Status smallint, @FileClosedDt datetime, @ReconV varchar(15), @GuestPrdComp smallint, @TermComp smallint, @FOID int, @FOName Varchar(100), @DistName Varchar(50), @ZName Varchar(50), @Model Varchar(150),

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #7

        Would make a good entry for the Code Horrors forum.

        1 Reply Last reply
        0
        • M mmdullah

          I have chacked it several times . Everything is fine . also the length for varchar types. the message not shown if I select into the first variable only. I don't know whats the problem with it . but I have wrote a lot of sp with such select into. :confused:

          J Offline
          J Offline
          jonhbt
          wrote on last edited by
          #8

          In the query you are building you have Select Distinct and when you are creating the cursor you have another SELECT. it can be that there is the problem. when it tis being executed you are havin

          SELECT SELECT DISTINCT...

          M 1 Reply Last reply
          0
          • P Pete OHanlon

            Your post is a database question, and you should post this in the database forum.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #9

            Pete O'Hanlon wrote:

            you should post this in the database forum

            It's a fantastic candidate for the "Coding Horrors" forum instead. :)

            It is a crappy thing, but it's life -^ Carlo Pallini

            M 1 Reply Last reply
            0
            • J jonhbt

              In the query you are building you have Select Distinct and when you are creating the cursor you have another SELECT. it can be that there is the problem. when it tis being executed you are havin

              SELECT SELECT DISTINCT...

              M Offline
              M Offline
              mmdullah
              wrote on last edited by
              #10

              No change takes place. Instead, would you please tell me the ways to open cursors excluding Open cursor cursor_NAme for select_statement I think as I provide the select_statement as a string variable , it may functioning another way thanks for your time br, mir

              1 Reply Last reply
              0
              • R Rajesh R Subramanian

                Pete O'Hanlon wrote:

                you should post this in the database forum

                It's a fantastic candidate for the "Coding Horrors" forum instead. :)

                It is a crappy thing, but it's life -^ Carlo Pallini

                M Offline
                M Offline
                mmdullah
                wrote on last edited by
                #11

                you know the sp has lots of code than high level language

                1 Reply Last reply
                0
                • M mmdullah

                  I have chacked it several times . Everything is fine . also the length for varchar types. the message not shown if I select into the first variable only. I don't know whats the problem with it . but I have wrote a lot of sp with such select into. :confused:

                  A Offline
                  A Offline
                  Ashfield
                  wrote on last edited by
                  #12

                  mmdullah wrote:

                  Everything is fine

                  No its not, otherwise you wouldn't be getting the error. The error TELLS you what is wrong, you need to double check it. At the end of the day, its right and you're wrong.

                  Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                  1 Reply Last reply
                  0
                  • M mmdullah

                    problem arises when fetching cursors. please help asap. the function code: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE FUNCTION Get_Coll_Ovd_Report ( @fromDate datetime, @ToDate datetime, @dtOvdDate datetime, @dtOvdDatePrev datetime, @strAndPaid VARCHAR(300), @rdoFileInfoSpecific int, @SpecificFileNo varchar(20), @strAndFOfficer varchar(100), @strAndZone varchar(100), @strCollType varchar(50), @rdoStatusNID smallint, @rdoStatusBankOpen smallint, @chkOvdVal smallint, @rdoRepTypeAllDet smallint )Returns @retVal table( [SLNo] int, [TDate] DateTime, [GLRef] Varchar(50), [LdgAcNo] Varchar(50), [AcName] Varchar(200), [MRNo] int, [GLName] Varchar(200), [Cash] decimal(18,6), [Clear] decimal(18,6), [Trans] decimal(18,6), [CnTot] decimal(18,6), [FileNo] Varchar(50), [NidStat] smallint, [UserID] Varchar(50), [District] Varchar(50), [PaidAt] Varchar(50), [ZMrNo] Varchar(50), [ZMrDate] DateTime, [Model] Varchar(50), [FOID] int, [FClBal] decimal(18,6), [TotCol] decimal(18,6), [BLoan] decimal(18,6), [BTotDr] decimal(18,6), [OvdPrv] decimal(18,6), [P1] decimal(18,6), [P2] decimal(18,6)) AS BEGIN declare @f_SLNo int,@f_TDate datetime,@f_GLRef varchar(50), @f_LdgAcNo varchar(50) , @f_AcName varchar(200) , @f_MRNo int, @f_GLName varchar(50), @f_Cash decimal(18,6), @f_Clear decimal(18,6), @f_Trans decimal(18,6), @f_CnTot decimal(18,6), @f_FileNo varchar(30) , @f_NidStat smallint , @f_UserID varchar(50), @f_District varchar(50) , @f_PaidAt Varchar(50), @f_ZMrNo Varchar(50), @f_ZMrDate datetime, @f_Model Varchar(50) , @f_FOID int, @f_FClBal decimal(18,6), @f_TotCol decimal(18,6), @f_BLoan decimal(18,6), @f_BTotDr decimal(18,6), @f_OvdPrv decimal(18,6), @f_P1 decimal(18,6), @f_P2 decimal(18,6) declare @strSQL varchar(2000), @LdgAcNo varchar(12), @MAcName varchar(80), @FileNo varchar(30), @MaxiInstlAmt decimal(18,0), @MaxiMinInstlAmt decimal(18,0), @DCPDt datetime, @FClBal decimal(18,6), @Ac_Status smallint, @FileClosedDt datetime, @ReconV varchar(15), @GuestPrdComp smallint, @TermComp smallint, @FOID int, @FOName Varchar(100), @DistName Varchar(50), @ZName Varchar(50), @Model Varchar(150),

                    P Offline
                    P Offline
                    PandemoniumPasha
                    wrote on last edited by
                    #13

                    The problem is here:

                    mmdullah wrote:

                    declare curMain cursor for select @strsql

                    the select statement selects a string not a result set! no need to write all that code to generate the error, a simple script of 4/5 lines will do the trick! ;P

                    regards :)

                    1 Reply Last reply
                    0
                    • M mmdullah

                      problem arises when fetching cursors. please help asap. the function code: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE FUNCTION Get_Coll_Ovd_Report ( @fromDate datetime, @ToDate datetime, @dtOvdDate datetime, @dtOvdDatePrev datetime, @strAndPaid VARCHAR(300), @rdoFileInfoSpecific int, @SpecificFileNo varchar(20), @strAndFOfficer varchar(100), @strAndZone varchar(100), @strCollType varchar(50), @rdoStatusNID smallint, @rdoStatusBankOpen smallint, @chkOvdVal smallint, @rdoRepTypeAllDet smallint )Returns @retVal table( [SLNo] int, [TDate] DateTime, [GLRef] Varchar(50), [LdgAcNo] Varchar(50), [AcName] Varchar(200), [MRNo] int, [GLName] Varchar(200), [Cash] decimal(18,6), [Clear] decimal(18,6), [Trans] decimal(18,6), [CnTot] decimal(18,6), [FileNo] Varchar(50), [NidStat] smallint, [UserID] Varchar(50), [District] Varchar(50), [PaidAt] Varchar(50), [ZMrNo] Varchar(50), [ZMrDate] DateTime, [Model] Varchar(50), [FOID] int, [FClBal] decimal(18,6), [TotCol] decimal(18,6), [BLoan] decimal(18,6), [BTotDr] decimal(18,6), [OvdPrv] decimal(18,6), [P1] decimal(18,6), [P2] decimal(18,6)) AS BEGIN declare @f_SLNo int,@f_TDate datetime,@f_GLRef varchar(50), @f_LdgAcNo varchar(50) , @f_AcName varchar(200) , @f_MRNo int, @f_GLName varchar(50), @f_Cash decimal(18,6), @f_Clear decimal(18,6), @f_Trans decimal(18,6), @f_CnTot decimal(18,6), @f_FileNo varchar(30) , @f_NidStat smallint , @f_UserID varchar(50), @f_District varchar(50) , @f_PaidAt Varchar(50), @f_ZMrNo Varchar(50), @f_ZMrDate datetime, @f_Model Varchar(50) , @f_FOID int, @f_FClBal decimal(18,6), @f_TotCol decimal(18,6), @f_BLoan decimal(18,6), @f_BTotDr decimal(18,6), @f_OvdPrv decimal(18,6), @f_P1 decimal(18,6), @f_P2 decimal(18,6) declare @strSQL varchar(2000), @LdgAcNo varchar(12), @MAcName varchar(80), @FileNo varchar(30), @MaxiInstlAmt decimal(18,0), @MaxiMinInstlAmt decimal(18,0), @DCPDt datetime, @FClBal decimal(18,6), @Ac_Status smallint, @FileClosedDt datetime, @ReconV varchar(15), @GuestPrdComp smallint, @TermComp smallint, @FOID int, @FOName Varchar(100), @DistName Varchar(50), @ZName Varchar(50), @Model Varchar(150),

                      D Offline
                      D Offline
                      David Skelly
                      wrote on last edited by
                      #14

                      I'm not a T-SQL expert so I may be wrong here. On the other hand, if you want the opinion of database experts you should probably have posted this in the database forum. I suspect that: declare curMain cursor for select @strsql will select the literal contents of the variable strsql. It seems to me that you will need to exec the strsql variable, or whatever the T-SQL equivalent is, in order to get it to run as an actual query. Of course, if anyone from the database forum happens to be passing by and knows better than me, please feel free to correct me.

                      1 Reply Last reply
                      0
                      • M mmdullah

                        problem arises when fetching cursors. please help asap. the function code: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE FUNCTION Get_Coll_Ovd_Report ( @fromDate datetime, @ToDate datetime, @dtOvdDate datetime, @dtOvdDatePrev datetime, @strAndPaid VARCHAR(300), @rdoFileInfoSpecific int, @SpecificFileNo varchar(20), @strAndFOfficer varchar(100), @strAndZone varchar(100), @strCollType varchar(50), @rdoStatusNID smallint, @rdoStatusBankOpen smallint, @chkOvdVal smallint, @rdoRepTypeAllDet smallint )Returns @retVal table( [SLNo] int, [TDate] DateTime, [GLRef] Varchar(50), [LdgAcNo] Varchar(50), [AcName] Varchar(200), [MRNo] int, [GLName] Varchar(200), [Cash] decimal(18,6), [Clear] decimal(18,6), [Trans] decimal(18,6), [CnTot] decimal(18,6), [FileNo] Varchar(50), [NidStat] smallint, [UserID] Varchar(50), [District] Varchar(50), [PaidAt] Varchar(50), [ZMrNo] Varchar(50), [ZMrDate] DateTime, [Model] Varchar(50), [FOID] int, [FClBal] decimal(18,6), [TotCol] decimal(18,6), [BLoan] decimal(18,6), [BTotDr] decimal(18,6), [OvdPrv] decimal(18,6), [P1] decimal(18,6), [P2] decimal(18,6)) AS BEGIN declare @f_SLNo int,@f_TDate datetime,@f_GLRef varchar(50), @f_LdgAcNo varchar(50) , @f_AcName varchar(200) , @f_MRNo int, @f_GLName varchar(50), @f_Cash decimal(18,6), @f_Clear decimal(18,6), @f_Trans decimal(18,6), @f_CnTot decimal(18,6), @f_FileNo varchar(30) , @f_NidStat smallint , @f_UserID varchar(50), @f_District varchar(50) , @f_PaidAt Varchar(50), @f_ZMrNo Varchar(50), @f_ZMrDate datetime, @f_Model Varchar(50) , @f_FOID int, @f_FClBal decimal(18,6), @f_TotCol decimal(18,6), @f_BLoan decimal(18,6), @f_BTotDr decimal(18,6), @f_OvdPrv decimal(18,6), @f_P1 decimal(18,6), @f_P2 decimal(18,6) declare @strSQL varchar(2000), @LdgAcNo varchar(12), @MAcName varchar(80), @FileNo varchar(30), @MaxiInstlAmt decimal(18,0), @MaxiMinInstlAmt decimal(18,0), @DCPDt datetime, @FClBal decimal(18,6), @Ac_Status smallint, @FileClosedDt datetime, @ReconV varchar(15), @GuestPrdComp smallint, @TermComp smallint, @FOID int, @FOName Varchar(100), @DistName Varchar(50), @ZName Varchar(50), @Model Varchar(150),

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #15

                        Why are you using a cursor for this? A cursor is a very inefficient way of manipulating data, and as far as I can see, all you are doing is returning data. Why not use a stored function to return this data?

                        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                        My blog | My articles | MoXAML PowerToys | Onyx

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups