Is it not possible to use UPDATE within a function? I get the following err
or message for the following function:
Evan
- - - - - - - - - - - - - -
Server: Msg 443, Level 16, State 2, Procedure fn_GetNextDataVersion, Line 10
Invalid use of 'UPDATE' within a function.
CREATE FUNCTION dbo.fn_GetNextDataVersion(@.tb_pk int)
RETURNS bigint
AS
BEGIN
DECLARE @.nextDataVersion bigint
SET @.nextDataVersion = 1 + (SELECT DataVersion FROM tb_TableList WHERE tb_pk
= @.tb_pk)
UPDATE tb_TableList SET DataVersion = @.nextDataVersion WHERE tb_pk = @.tb_pk
RETURN @.nextDataVersion
ENDDDL statements inside user-defined functions are only allowed on table
variables local to the function.
http://msdn.microsoft.com/library/d...>
_08_460j.asp
Objects cannot be created, altered or dropped if they exist outside the
scope of the user-defined function.
ML
http://milambda.blogspot.com/|||Table variables IF a table is created in that function?
"ML" <ML@.discussions.microsoft.com> wrote in message
news:B2FA2009-C30A-4DF4-B8CE-DC110EA8F77A@.microsoft.com...
> DDL statements inside user-defined functions are only allowed on table
> variables local to the function.
> http://msdn.microsoft.com/library/d...
es_08_460j.asp
> Objects cannot be created, altered or dropped if they exist outside the
> scope of the user-defined function.
>
> ML
> --
> http://milambda.blogspot.com/|||Yes. Locally. Variables are always local in SQL.
("This is a local shop. For local people." -- from 'A League of Gentlemen'
(BBC))
What is your goal exactly - there might be another way. If you share the
goal. :)
ML
http://milambda.blogspot.com/|||Create a function which gets a counter from a table and return the counter
WHILE updating the counter table to PLUS ONE
Evan
"ML" <ML@.discussions.microsoft.com> wrote in message
news:854D1DA1-3C1C-45B7-8A9B-E787B3856E55@.microsoft.com...
> Yes. Locally. Variables are always local in SQL.
>
> ("This is a local shop. For local people." -- from 'A League of Gentlemen'
> (BBC))
>
> What is your goal exactly - there might be another way. If you share the
> goal. :)
>
> ML
> --
> http://milambda.blogspot.com/|||for now i am working with a stored proc but a function is more elegant|||If you want to do it in a single step, then the procedure is the way to go.
ML
http://milambda.blogspot.com/
No comments:
Post a Comment