Eugene's response to this post is one of the most amusing refutations I have ever seen on the net. I won't steal its thunder by quoting, just give it a read if you have 30 seconds to spare.
27 January 2006
Functions and procedures in MS SQL 2000 don't play particularly well together. That's not really a problem, seeing as they both solve the same problem: running a sequence of operations. But (and this is a particularly large but) functions offer only a subset of the range of operations available — most notably, they can't alter data in tables or create temporary tables.
So why would anyone use a function? They're particularly useful as they can return values. Unlike stored procedures which return an error-code and can pack output variables with data; functions return a value in much the same way as similar constructs in procedural languages.
The 'value' returned by a function can be a scalar value (int, bit, char, &c.) or.. a table. Scalar-valued functions are useful in a whole bunch of places, but the table-valued function is an interesting beastie. Table-valued functions behave like views with arguments, so for example:
a) select question from questions_view where answer=42 b) select question from questions_by_planet('earth') where answer=42In
a)
above, all planets would be interrogated for possible questions, those matched to possible answers, then filtered by the where clause. In b)
interrogation could be performed only on earth (saving a few planets along the way). In such scenarios, using a function over a view is far more efficient.
Right about now Mr S. Procedure's tappping me on the shoulder to say: "Hey buddy, I do that too.". Yes, okay, you can achieve the same thing with stored procedures, but they don't provide as elegant a solution. Functions can literally be dropped in the place of views as if they were merely a view with a more complex name; to return a table from a procedure requires (to the best of my knowledge) a pretty dance involving creating cursors into temporary tables.
Why did I feel the need to write all this down? Well, apart from the eminent utility of another description of the differences between functions and stored procedures in MS SQL, I intend to use it as a base from which to describe my recent problems and their resolution.Posted on Friday, January 27, 2006 by Unknown
Subscribe to:
Posts (Atom)
Popular Posts
-
In Boris Gloger 's "Estimation in Depth" deep dive at the South African Scrum Gathering he introduced us to Magic estimation....
-
The problem Stored in a varchar column, payload_xml , we have xml that looks something like this: <?xml version="1.0" encod...
-
A few years back I met a young soul exploring software development. He had programmed some robots, learnt some python and gotten himself to ...
-
Functions and procedures in MS SQL 2000 don't play particularly well together. That's not really a problem, seeing as they both sol...
-
This is the third in my Agile Contracting series . As with the previous post, this is a verbatim copy of my speech notes, with some mark-up...
-
Or, how I learned to read the assembly name In which I include dll's I was trying out this tutorial on Geekpedia and the references w...
-
All of us at Information Logistics took the break from routine to take part in the Scrum Safari . My mind's still processing the influx...
-
Mohamed Bray Sugsa August 2010 This month's sugsa was a cross-talk from the Business Analysis community. The Talk Mohamed describ...
-
Breaking it down: scrum i kanban agilistic xp lean i do cious Scrumikanbanagilisticxpleanidocious is a word I dreamed ...
-
On day 2 of the Cape Town Scrum Gathering (a.k.a. Scrum Safari) there were a few lightning talks in the afternoon. I was lucky enough to na...