Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Inserting results from extended stored proc into table variable within UD function generates error Expand / Collapse
Posted Thursday, August 13, 2009 5:52 PM


Group: General Forum Members
Last Login: Tuesday, December 29, 2015 8:05 PM
Points: 110, Visits: 269

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 ()
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


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!


Post #770590
Posted Thursday, August 13, 2009 7:00 PM

SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Tuesday, October 25, 2016 7:17 AM
Points: 9,298, Visits: 9,517
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:, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #770612
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse