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. Database & SysAdmin
  3. Database
  4. cursors in functions

cursors in functions

Scheduled Pinned Locked Moved Database
helpquestion
5 Posts 4 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.
  • S Offline
    S Offline
    Sonia Gupta
    wrote on last edited by
    #1

    CREATE FUNCTION [dbo].[waste] () RETURNS table AS declare @a int declare @b int BEGIN declare cur cursor for select a1,a2 from a open cur fetch next from a into @a,@b while @@FETCH_STATUS =0 BEGIN SELECT @a as a1 , @b as a2 fetch next from a into @a , @b END close cur deallocate cur return END where is the bug lying?

    Soniagupta1@yahoo.co.in Yahoo Messenger Id = soniagupta1

    K N 2 Replies Last reply
    0
    • S Sonia Gupta

      CREATE FUNCTION [dbo].[waste] () RETURNS table AS declare @a int declare @b int BEGIN declare cur cursor for select a1,a2 from a open cur fetch next from a into @a,@b while @@FETCH_STATUS =0 BEGIN SELECT @a as a1 , @b as a2 fetch next from a into @a , @b END close cur deallocate cur return END where is the bug lying?

      Soniagupta1@yahoo.co.in Yahoo Messenger Id = soniagupta1

      K Offline
      K Offline
      Krish KP
      wrote on last edited by
      #2

      1. remove BEGINafter the Decleration of A & B 2. and include before before A & B

      Regards KP

      S 1 Reply Last reply
      0
      • K Krish KP

        1. remove BEGINafter the Decleration of A & B 2. and include before before A & B

        Regards KP

        S Offline
        S Offline
        Sonia Gupta
        wrote on last edited by
        #3

        CREATE FUNCTION [dbo].[waste] () RETURNS table AS declare @a int declare @b int declare cur cursor for select a1,a2 from a open cur fetch next from a into @a,@b while @@FETCH_STATUS =0 BEGIN SELECT @a as a1 , @b as a2 fetch next from a into @a , @b END close cur deallocate cur return GO Now it is saying incorect syntax near the keyword declare. return statement statement i scalar valued function must include an argument

        Soniagupta1@yahoo.co.in Yahoo Messenger Id = soniagupta1

        R 1 Reply Last reply
        0
        • S Sonia Gupta

          CREATE FUNCTION [dbo].[waste] () RETURNS table AS declare @a int declare @b int declare cur cursor for select a1,a2 from a open cur fetch next from a into @a,@b while @@FETCH_STATUS =0 BEGIN SELECT @a as a1 , @b as a2 fetch next from a into @a , @b END close cur deallocate cur return GO Now it is saying incorect syntax near the keyword declare. return statement statement i scalar valued function must include an argument

          Soniagupta1@yahoo.co.in Yahoo Messenger Id = soniagupta1

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          youre declaring that the fn will return a table and look at the last line

          Sonia Gupta wrote:

          return GO

          whats happening here??

          Rocky You can't climb up a ladder with your hands in your pockets.

          1 Reply Last reply
          0
          • S Sonia Gupta

            CREATE FUNCTION [dbo].[waste] () RETURNS table AS declare @a int declare @b int BEGIN declare cur cursor for select a1,a2 from a open cur fetch next from a into @a,@b while @@FETCH_STATUS =0 BEGIN SELECT @a as a1 , @b as a2 fetch next from a into @a , @b END close cur deallocate cur return END where is the bug lying?

            Soniagupta1@yahoo.co.in Yahoo Messenger Id = soniagupta1

            N Offline
            N Offline
            neeraj_indianic
            wrote on last edited by
            #5

            You have not specified that which type of function you want to create means scalar valued function or table valued function. I suppose that you want to create table valued function. For that your code is wrong in the starting line. Look at the below code. Hope it will guide you. CREATE FUNCTION [dbo].[waste]() RETURNS @student1 TABLE ( student_rec int, St_name nchar(10) ) AS Begin declare @a int declare @b nchar(10) declare cur cursor for select Id,name from student open cur fetch next from cur into @a,@b while @@FETCH_STATUS =0 BEGIN INSERT @student1 values(@a,@b) --SELECT @a as a1 , @b as a2 fetch next from cur into @a , @b END close cur deallocate cur RETURN end Neeraj Gupta IndiaNIC Infotech Ltd.

            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