Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Author
Message
Posted Thursday, August 13, 2009 5:52 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, June 29, 2014 5:12 PM
Points: 103, Visits: 243
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
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: Yesterday @ 11:52 AM
Points: 9,294, Visits: 9,484
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."
Post #770612
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse