Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Inserting results from extended stored proc into table variable within UD function generates error


Inserting results from extended stored proc into table variable within UD function generates error

Author
Message
Simon Bailey
Simon Bailey
SSC-Enthusiastic
SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)

Group: General Forum Members
Points: 118 Visits: 269
Hi,

We have a mixture of 32-bit and 64-bit database servers, all running SS2K5 SP2.

In various scripts and procedures (particulary when executing an SSIS package using DTExec), I need to know which platform I am running from (ie 32-bit or 64-bit).

I am trying to create a function that will simply tell me whether it is 64-bit or 32-bit. Here is the code:

CREATE FUNCTION dbo.fnS_Is_64bit_SQL ()
RETURNS bit
AS
BEGIN
DECLARE @Is64bit bit
DECLARE @MSVer table(
[Index] int not null,
[Name] varchar(255) not null,
Internal_Value int null,
Character_Value varchar(1024) null
)

INSERT INTO @MSVer ([Index], [Name], Internal_Value, Character_Value)
EXEC xp_msver 'FileDescription'

SELECT @Is64bit = CASE WHEN charindex('64', Character_Value, 1) > 0 THEN 1 ELSE 0 END
FROM @MSVer

RETURN @Is64Bit
END



It generates an error message when trying to create the function:

"Invalid use of side-effecting or time-dependent operator in 'INSERT EXEC' within a function."

According to BOL, the following are all valid within UDFs

"UPDATE, INSERT, and DELETE statements modifying table variables that are local to the function."
"EXECUTE statements calling an extended stored procedure."

Why am I unable to create this function?

Any assistance gratefully received!

Thanks,

Simon
RBarryYoung
RBarryYoung
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10502 Visits: 9517
Well both Functions and INSERT..EXEC have a lot of restrictions on them. So many in fact that AFAIK, you cannot use INSERT_EXEC in a user-defined function, because:

- INSERT..EXEC cannot be used to write to table variables, and...

- User-Defined functions cannot write to any other kind of table.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search