Running script without having permission to Function

  • Good Morning.

    I have a T-SQL Script which has been developed to execute a Function1 (which itself calls another Function2). Unfortunately I do not have permission to execute these functions. Hence I am trying to re-write the Script to enable the core logic of these functions to be incorporated in to it.

    1. Function1 takes TWO parameters, and returns a Table

    CREATE FUNCTION [dbo].[Function1] (@Param1 int, @Param2 varchar)

    RETURNS TABLE

    AS

    RETURN

    (

    WITH CTE_O AS

    (SELECT F1 AS Field_O

    FROM Table1

    WHERE ODGUID = @Param1

    )

    SELECT *

    FROM dbo.Function2 (@Param1, @Param2, (SELECT TOP (1) Field_O FROM CTE_O) )

    );

     

    2) Function2 takes THREE parameters (two of which are exactly the same two parameters required by Function1). Function2 returns a Table which it passes back to Function1:

    CREATE FUNCTION [dbo].[Function2]

    (

    @Param1 int,

    @Param2 varchar,

    @Field1 int

    )

    RETURNS TABLE

    AS

    RETURN

     

    Kindly advise on a suitable structure to implement these two functions within my current Script.

    • This topic was modified 3 weeks, 1 days ago by Reh23.
  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • without knowing the code of Function2 we can't help there. it may or not be possible/easy - but if function2 returns more than 1 row (first 1 returns a single row to pass to function2) then it may be tricker.

     

    BUT.. if you have access to read the data on that database, then  you should also be granted access to select/execute functions. Ask your admin for it.

  • It's not completely clear what you want to do here. What is your script and what do you want returned? Are you trying to re-implement two functions you can't execute?

    As Frederico noted, you need access to get the code of function2, but also, you should think about how to better explain what you want to have happen.

  • Reh23 wrote:

    Unfortunately I do not have permission to execute these functions. Hence I am trying to re-write the Script to enable the core logic of these functions to be incorporated in to it.

    That's the whole key here.  Whoever setup the second function either deliberately limited who run the function (possibly due to the sensitivity of the data it returns) or did so accidentally.

    You need to get with the DBA and/or the people that own the function and get the necessary privs.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply