rourrourlogan (4/26/2015)
I want to find out the sum of the total new insurance policies quickly, I dont want to have to navigate an entire long list of querys to find what I find.. I just want to highlight a function like..Call Query 1
and it runs a select statement.. such as.. Select sum(NewInsurancePolicy) From Database where Flag = 40
Depending on how you use such a thing, it could be a recipe for disaster or it could be your best friend.
There are three things you should lookup and learn how to use because all three can do what you ask. Stored Procedures, Inline Table Valued Functions (iTVF for future reference), and Views. All have advantages and disadvantages. All of them, of course, have the advantage of code abstraction. All of them, of course, have the disadvantage of code obfuscation. You can seriously go overboard with abstraction in T-SQL just like you can in any language.
Although there are ways to call stored procedures, iTVFs, and Views in similar fashions, stored procedures are normally "called" using either the EXEC or EXECUTE keyword. iTVFs and Views are normally "called" by including them in the FROM clause of a SELECT, INSERT, UPDATE, DELETE, or MERGE statement of one form or another.
--Jeff Moden
Change is inevitable... Change for the better is not.