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. not sure of advantages of functions over stored procedures

not sure of advantages of functions over stored procedures

Scheduled Pinned Locked Moved Database
help
6 Posts 3 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
    sishya
    wrote on last edited by
    #1

    Hi, I am asked to convert stored procedures to functions .Can anyone tell me the advantages of functions over stored procedures and vice versa and i am not shoor if i can use system ftions like getdate() in functions pls help me out thnks in advance.

    J C 2 Replies Last reply
    0
    • S sishya

      Hi, I am asked to convert stored procedures to functions .Can anyone tell me the advantages of functions over stored procedures and vice versa and i am not shoor if i can use system ftions like getdate() in functions pls help me out thnks in advance.

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Functions are useful when you only need to return a single value from a procedure, rather than a set of data. You can use all built in functions as you would in a SP, the only limitation AFAIK is that you cannot insert/update from a function. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

      C 1 Reply Last reply
      0
      • J J4amieC

        Functions are useful when you only need to return a single value from a procedure, rather than a set of data. You can use all built in functions as you would in a SP, the only limitation AFAIK is that you cannot insert/update from a function. Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        J4amieC wrote:

        You can use all built in functions as you would in a SP

        You can't use functions such as GETDATE() because they are non-deterministic.


        Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        J 1 Reply Last reply
        0
        • S sishya

          Hi, I am asked to convert stored procedures to functions .Can anyone tell me the advantages of functions over stored procedures and vice versa and i am not shoor if i can use system ftions like getdate() in functions pls help me out thnks in advance.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          sishya wrote:

          Can anyone tell me the advantages of functions over stored procedures and vice versa and i am not shoor if i can use system ftions like getdate() in functions pls help me out

          You cannot use functions such as GETDATE() because they are non-deterministic. A function must have a deterministic operation. i.e. Given the same inputs it will always produce the same output. I wouldn't go around and convert stored procedures to functions just because. I wouldn't say functions or stored procedures have any avantages over each other. They are designed for different uses. A function can return data to calling code more easily that a stored procedure can. A stored procedure can perform data modification actions (INSERT/UPDATE/DELETE) that a function can't.


          Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            J4amieC wrote:

            You can use all built in functions as you would in a SP

            You can't use functions such as GETDATE() because they are non-deterministic.


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

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

            Live and learn, of the countless times ive used UDF's ive never come across this! Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

            C 1 Reply Last reply
            0
            • J J4amieC

              Live and learn, of the countless times ive used UDF's ive never come across this! Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              J4amieC wrote:

              Live and learn

              Absolutely - the day we stop learning is the day we die.


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              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