Retrieval T-SQL Function

Posts   
 
    
CoUgar
User
Posts: 3
Joined: 12-Mar-2007
# Posted on: 12-Mar-2007 15:02:45   

Hi,

I have a question that I couldn't find any answer for it in the documentation.

I have a function that returns a table ;


CREATE FUNCTION dbo.fGetChainHotelsCountries
 (  
    @chainId nvarchar(38),
    @status int
 )  
RETURNS TABLE 
 AS  
RETURN (    SELECT DISTINCT HotelBasis.HotelID, Countries.CountryID, Countries.CountryEn
        FROM  HotelBasis with(nolock)  INNER JOIN
                    Countries ON HotelBasis.CountryID = Countries.CountryID
        WHERE    (HotelBasis.HotelStatus = @status) AND (HotelBasis.ChainID = @chainId)   
         )

I want to get it to a DataTable. Is there anyway for doing that? Can DbFunctionCall help me anyway? All examples are for the scenario where function returns scalar.

I am considering to get connection from Llblgen with DbUtils.CreateConnection() and use .net standart SqlCommands to execute the sqlstatement "select * from fGetChainHotelsCountries .."

I want to be sure that there is no "nice" way of doing it in Llblgen.

Thanks. Cheers

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 12-Mar-2007 15:44:52   

Hi,

You can read this thread, witch is similar :

http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=14378&ThreadID=2547

cheers,

Aurélien

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 12-Mar-2007 16:13:05   

(Watching to see the answer to this thread)....

Aurelien, that thread you pointed to does not seem to have anything to do with this question.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 12-Mar-2007 16:21:33   

Hi,

browse to the procedure in the catalog, click open the node and select #0, then right click and select the menu entry to change the value to 1 or 2 (1 will result in a datatable, 2 in a dataset).

there is in the both cases a stored procedure witch return a table.

CoUgar
User
Posts: 3
Joined: 12-Mar-2007
# Posted on: 12-Mar-2007 16:39:30   

Thanks for your prompt help but I couldn't understand how it is related with my question.

SQL T-SQL function is not so important.

Let's say I have an function in the sql server that returns a table. Now I would like to have it available in the object oriented world that Llblgen supplies to me.

If it was a SP instead of a function, I would be using it with StoredProcedureCallerClasses.

It's unclear how to use it if it is a function. As you know, it should send a sql code like

"select myfield1,myfield2 from myfunction()"

In the example you sent, discussion was about StoredProcedures, the thing is I am trying to migrate an existing project to Llblgen and there are lots of functions already written. I can't convert them, I should be using them instead.

Thanks, Regards.

PS: I am using Llblgen Pro 2.0.0.0 Final (February 14th,2007) with self servicing behavior.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 12-Mar-2007 17:22:16   

Hi,

Ok, my mistake, i read stored procedure instead of function confused

So I don't see a way to solve your problem with DbFunctionCall. By the way, you can use DataAccessAdapterBase.ExecuteMultiRowDataTableRetrievalQuery or DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery to execute sql statments.

CoUgar
User
Posts: 3
Joined: 12-Mar-2007
# Posted on: 12-Mar-2007 17:32:56   

Thanks for the hint. I'll prepare sql statements with functions inside it and run them with the methods you given.