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