Domanda

If I have a function like this

dbo.GetTable(@myInteger) 

can I select columns by name from the resulting table, and assign them to variables in a subsequent function in SQL Server 2005?

Or is it more efficient in the subsequent function to create a temporary table and populate it with the results of

dbo.GetTable(@myInteger) 

This way you only call the above function once instead of going something like

DECLARE @IntegerOne Integer = dbo.GetTable(@myInteger).Column1
DECLARE @IntegerTwo Integer = dbo.GetTable(@myInteger).Column2
DECLARE @IntegerThree Integer = dbo.GetTable(@myInteger).Column3

etc

È stato utile?

Soluzione

If it is a table valued function you can treat it just like a table and you can do something like ....

DECLARE @IntegerOne Integer; 
DECLARE @IntegerTwo Integer;
DECLARE @IntegerThree Integer;

SELECT TOP 1                    --<-- To make sure only one row is returned
        @IntegerOne   = Column1
       ,@IntegerTwo   = Column2
       ,@IntegerThree = Column3
FROM dbo.GetTable(@myInteger)
--WHERE Clause if required  

Altri suggerimenti

Not sure if I got your question correct, for table function this will work:

select
    @IntegerOne = Column1,
    @IntegerTwo = Column2,
    @IntegerThree = Column3
from dbo.GetTable(@myInteger)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top