7 Replies - 576 Views - Last Post: 02 November 2017 - 09:14 AM

#1 aidenkael   User is offline

  • D.I.C Regular
  • member icon

Reputation: 66
  • View blog
  • Posts: 309
  • Joined: 22-October 13

Is it possible to create a local function?

Posted 24 October 2017 - 09:57 AM

What I mean by this, is a function that is saved to your machine only. This differs from a function because the function is saved in the database, and it differs from a temp function because the temp function is gone when you close the instance it resides in. An example of this could be:
CREATE LOCAL FUNCTION AddNumbers(
	@One INT,
	@Two INT
) 
RETURNS INT
AS
BEGIN
	DECLARE @Result AS INT = @One + @Two
	RETURN @Result
END



I would be able to call this like any normal function from my machine, but no one else would have access to it, and the database would not store it.

Is this possible? Or a pipe dream?

Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to create a local function?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14859
  • View blog
  • Posts: 59,283
  • Joined: 12-June 08

Re: Is it possible to create a local function?

Posted 24 October 2017 - 10:00 AM

You certainly can save a .SQL file to your local machine or have the SQL query embedded in some code.
Was This Post Helpful? 0
  • +
  • -

#3 aidenkael   User is offline

  • D.I.C Regular
  • member icon

Reputation: 66
  • View blog
  • Posts: 309
  • Joined: 22-October 13

Re: Is it possible to create a local function?

Posted 24 October 2017 - 01:00 PM

View Postmodi123_1, on 24 October 2017 - 12:00 PM, said:

You certainly can save a .SQL file to your local machine or have the SQL query embedded in some code.


Yeah, I have it saved in a script right now, but I was hoping I could make it local and distribute it to other folks I work with so that they can use it easily and not have to see the mass of code behind it.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14859
  • View blog
  • Posts: 59,283
  • Joined: 12-June 08

Re: Is it possible to create a local function?

Posted 24 October 2017 - 01:10 PM

I don't get what you mean "make it local". You have the query local in a .SQL file on your desktop. Not much more local than that.
Was This Post Helpful? 0
  • +
  • -

#5 aidenkael   User is offline

  • D.I.C Regular
  • member icon

Reputation: 66
  • View blog
  • Posts: 309
  • Joined: 22-October 13

Re: Is it possible to create a local function?

Posted 25 October 2017 - 03:38 PM

View Postmodi123_1, on 24 October 2017 - 03:10 PM, said:

I don't get what you mean "make it local". You have the query local in a .SQL file on your desktop. Not much more local than that.


I guess the best way to describe it is the ability to call the function like any other standard function. I.e.,

SELECT dbo.AddNumbers(1,2)



The local part in this case just means "not stored on the database".
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14859
  • View blog
  • Posts: 59,283
  • Joined: 12-June 08

Re: Is it possible to create a local function?

Posted 26 October 2017 - 06:38 AM

Then no. A database server would not have access to scan/know what you have on your local machine.

I am not sure why you wouldn't store it on the DB, but so it goes.
Was This Post Helpful? 0
  • +
  • -

#7 aidenkael   User is offline

  • D.I.C Regular
  • member icon

Reputation: 66
  • View blog
  • Posts: 309
  • Joined: 22-October 13

Re: Is it possible to create a local function?

Posted 02 November 2017 - 07:54 AM

View Postmodi123_1, on 26 October 2017 - 08:38 AM, said:

I am not sure why you wouldn't store it on the DB, but so it goes.


May I present our database engineers, who (and I kid you not), refuse to tie tables based on the identity column...... They "don't want functions cluttering up the database".
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6744
  • View blog
  • Posts: 27,758
  • Joined: 12-December 12

Re: Is it possible to create a local function?

Posted 02 November 2017 - 09:14 AM

I don't know if this might be a consideration, it creates a global temporary procedure. It is not local, but nor is stored with the main database.

Anyway... just a thought ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1