Friday, February 24, 2012

Global Function in 2005

Hi,
I'm trying to create a global function in SQL Server 2005. I mean, a
function similar to GETDATE(), that is public for all databases.
This is possible in SQL Server 2000, but I don't find any similar in
2005
Thanks in advance
--
--
--
Un saludo
--
---
"Slo s que no s nada. " (Scrates)Carlos Sacristn (csacristanARROBAmvpsPUNTOorg) writes:
> I'm trying to create a global function in SQL Server 2005. I mean, a
> function similar to GETDATE(), that is public for all databases.
> This is possible in SQL Server 2000, but I don't find any similar in
> 2005
I guess this was possible in SQL 2000 by creating functions in master and
make them look like system functions as fn_get_trace_status(). However,
that was entirely unsupported.
In SQL 2005, system procedures and system functions are stored in the
invisible resource database.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks Edgar,
I know this was unsupported, but the applications that actually run
against SQL Server 2000 use this feature, so I trying to do the same in
2005. Do you know any way to get something similar?
I try with synonyms, but it's no possible
--
--
--
Un saludo
--
---
"Slo s que no s nada. " (Scrates)
"Erland Sommarskog" <esquel@.sommarskog.se> escribi en el mensaje
news:Xns97D38A59F23A4Yazorman@.127.0.0.1...
> Carlos Sacristn (csacristanARROBAmvpsPUNTOorg) writes:
> I guess this was possible in SQL 2000 by creating functions in master and
> make them look like system functions as fn_get_trace_status(). However,
> that was entirely unsupported.
> In SQL 2005, system procedures and system functions are stored in the
> invisible resource database.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx|||Carlos Sacristn (csacristanARROBAmvpsPUNTOorg) writes:
> I know this was unsupported, but the applications that actually run
> against SQL Server 2000 use this feature, so I trying to do the same in
> 2005. Do you know any way to get something similar?
Moral: don't rely on unsupported and undocumented behaviour.

> I try with synonyms, but it's no possible
Synonyms sounds as the best bet, but you would have to install them in
every database. And the functions can not operate on tables in the local
database.
You will have to back to the drawing-board, I guess.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Bad news, really...
In my case, I don't need the functions to operate with tables. There are
scalar function, for example, something like
CREATE FUNCTION dbo.fn_Trim (@.par VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
RETURN RTRIM(LTRIM(@.par))
END
I think that the possibility to create this type of scalar-functions
(globals for all databases) could be an interesting feature.
Anyway, thanks for your help Erland
--
--
--
Un saludo
--
---
"Slo s que no s nada. " (Scrates)
"Erland Sommarskog" <esquel@.sommarskog.se> escribi en el mensaje
news:Xns97D39FFD079A1Yazorman@.127.0.0.1...
> Carlos Sacristn (csacristanARROBAmvpsPUNTOorg) writes:
> Moral: don't rely on unsupported and undocumented behaviour.
>
> Synonyms sounds as the best bet, but you would have to install them in
> every database. And the functions can not operate on tables in the local
> database.
> You will have to back to the drawing-board, I guess.
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx|||Carlos Sacristn (csacristanARROBAmvpsPUNTOorg) writes:
> In my case, I don't need the functions to operate with tables. There
> are scalar function, for example, something like
> CREATE FUNCTION dbo.fn_Trim (@.par VARCHAR(8000))
> RETURNS VARCHAR(8000)
> AS
> BEGIN
> RETURN RTRIM(LTRIM(@.par))
> END
> I think that the possibility to create this type of scalar-functions
> (globals for all databases) could be an interesting feature.
On http://lab.msdn.microsoft.com/ProductFeedback/ you can submit a
suggestion for this to be added ot a future release of SQL Server.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment