sChapman
2012-02-29 10:19:40 UTC
Hi ,
I have a situation where I need to perform calculations on the columns
within a SELECT result set. These calculations can repeat. I have
provided a sample of these calculations, in reality they are much,
much more complicated. The best way I have found to achieve this is by
writing stored functions and calling these as part of SELECT. But the
database on which the SELECT is running, the user will not have
permission to CREATE functions. I can't create the functions as SA
either as these databases are 3rd Party databases and I can't fiddle
with them. I have explored temporary stored functions but these are
not supported. But temporary stored proecedures are.... any idea how I
can create/simulate TEMPORARY STORED FUNCTIONS?
Example of SELECT:
SELECT X,Y, (X+Y) AS [Sum], (X-Y) AS [Diff}, (X*Y) AS [Product]
FROM MyTable
Same thing using Functions
SELECT X,Y,
DBO.MyAdd(X,Y) AS [Sum],
DBO.MyDiff(X,Y) AS [Diff],
DBO.MyMult(X,Y) AS [Prod]
FROM MyTable
I have a situation where I need to perform calculations on the columns
within a SELECT result set. These calculations can repeat. I have
provided a sample of these calculations, in reality they are much,
much more complicated. The best way I have found to achieve this is by
writing stored functions and calling these as part of SELECT. But the
database on which the SELECT is running, the user will not have
permission to CREATE functions. I can't create the functions as SA
either as these databases are 3rd Party databases and I can't fiddle
with them. I have explored temporary stored functions but these are
not supported. But temporary stored proecedures are.... any idea how I
can create/simulate TEMPORARY STORED FUNCTIONS?
Example of SELECT:
SELECT X,Y, (X+Y) AS [Sum], (X-Y) AS [Diff}, (X*Y) AS [Product]
FROM MyTable
Same thing using Functions
SELECT X,Y,
DBO.MyAdd(X,Y) AS [Sum],
DBO.MyDiff(X,Y) AS [Diff],
DBO.MyMult(X,Y) AS [Prod]
FROM MyTable