Function Call With Table As Parameter

Jul 23, 2005

Hi all, I want to use a function with a tabel object as parameter. Does
someone know a method to do this. I have read that a table as parameter
is invalid.

View 4 Replies


ADVERTISEMENT

Function To Call Function By Name Given As Parameter

Jul 20, 2005

I want to write function to call another function which name isparameter to first function. Other parameters should be passed tocalled function.If I call it function('f1',10) it should call f1(10). If I call itfunction('f2',5) it should call f2(5).So far i tried something likeCREATE FUNCTION [dbo].[func] (@f varchar(50),@m money)RETURNS varchar(50) ASBEGINreturn(select 'dbo.'+@f+'('+convert(varchar(50),@m)+')')ENDWhen I call it select dbo.formuła('f_test',1000) it returns'select f_test(1000)', but not value of f_test(1000).What's wrong?Mariusz

View 3 Replies View Related

SQL Server 2012 :: Call A Split Parameter Function

Sep 15, 2014

In t-sql 2012, the followinng sql works fine when I declare @reportID.

IF @reportID <> 0
BEGIN
SELECT 'Students report 1' AS selectRptName, 1 AS rptNumValue
UNION
SELECT 'Students report 2', 2
UNION

[code]...

However when I use the sql above in an ssrs 2012 report, the query does not work since the @reportID parameter can have 0, 1, or up to 200 values.Thus I am thinking of calling the following following function to split out the parameter values:

FUNCTION [dbo].[fn_splitString]
(
@listString VARCHAR(MAX)
)
RETURNS TABLE WITH SCHEMABINDING
AS
RETURN
(
SELECT SUBSTRING(l.listString, sn.Num + 1, CHARINDEX(',', l.listString, sn.Num + 1) - sn.Num - 1) _id
FROM (SELECT ',' + LTRIM(RTRIM(@listString)) + ',' AS listString) l
CROSS JOIN dbo.sequenceNumbers sn
WHERE sn.Num < LEN(l.listString)
AND SUBSTRING(l.listString, sn.Num, 1) = ','
)

GO

how to remove the @reportID <> 0 t-sql above and replace by calling the fn_splitString function?

View 2 Replies View Related

How To Call A Function From A Column Formula In My MS SQL Table

Apr 24, 2007

Good day!

What is the syntax on calling a function from a column formula in an MS SQL table.

I created a table, one column's value will be coming from a function. And at the same time, I will pass parameters to the function. How do I do this? Is this correct?

SELECT dbo.FunctionName([Parameter1, Parameter2])

But i can't save the table, "Error validating the formula".

Pls. help
Thanks a lot.

View 3 Replies View Related

Reporting Services :: How To Call Table Value Function In SSRS

Sep 23, 2015

How to call a table valued functions from SSRS reports ? 

Is there a way to call by selecting Dataset properties> Query >Stored Procedure radio button, If not then why our object type function is visible under this list.

MS SQL Server 2008 R2

View 5 Replies View Related

SQL Server 2012 :: Table Returning Function With Input Table Name As Parameter

Nov 19, 2014

I'm using SS 2012.

I started with an inline table returning function with a hard coded input table name. This works fine, but my boss wants me to generalize the function, to give it in input table parameter. That's where I'm running into problems.

In one forum, someone suggested that an input parameter for a table is possible in 2012, and the example I saw used "sysname" as the parameter type. It didn't like that. I tried "table" for the parameter type. It didn't like that.

The other suggestion was to use dynamic sql, which I assume means I can no longer use an inline function.

This means switching to the multi-line function, which I will if I have to, but those are more tedious.

Any syntax for using the inline function to accomplish this, or am I stuck with multi-line?

A simple example of what I'm trying to do is below:

Create FUNCTION [CSH388102].[fnTest]
(
-- Add the parameters for the function here
@Source_Tbl sysname
)
RETURNS TABLE
AS
RETURN
(
select @Source_Tbl.yr from @Source_Tbl
)

Error I get is:

Msg 1087, Level 16, State 1, Procedure fnTest, Line 12
Must declare the table variable "@Source_Tbl".

If I use "table" as the parameter type, it gives me:

Msg 156, Level 15, State 1, Procedure fnTest, Line 4
Incorrect syntax near the keyword 'table'.
Msg 137, Level 15, State 2, Procedure fnTest, Line 12
Must declare the scalar variable "@Source_Tbl".

The input table can have several thousand rows.

View 9 Replies View Related

Table Name As Function Parameter

Mar 2, 2008

I'm trying to write a function that I can run with passing the table name as a parameter. I want to return an integer. The tables wll be differnet types (different colums) but they all have a similar field that i want to get a count of. Someting alng the lines of this:

Create FUNCTION [dbo].[fn_GetItemsToPromote]
(
@TableName nvarchar(100)
)
RETURNS int
AS
BEGIN
Declare @SQL nvarchar(500)
return select count(*) from [@TableName]where promote = 1
END

It doesnt like the @TableName. Can anyone show me how to do this correctly?

Thanks!

View 4 Replies View Related

Function That Take A Table As Input Parameter

Feb 26, 2008

hi all
i am using VS 2005 with SQL Server 2005 and i faced a problem that need to be solved urgently...
i want to make a function that take a table as input parameter which is the output of a stored procedure (Record set)...
first i found that to make w table be as input parameter you must create type of that table first but i found that sql server 2005 doesn't have the 'table' as a type...
please any help will be appreciated
thanks in advance

View 2 Replies View Related

Passing Table Name As Parameter To Function

May 24, 2008

Hi all.

I'm writing reports in Rep. Services that reads data from Dynamics NAV (Navision). In NAV data are stored by company and this is implemented by using the company name as prefix to the table name. This means that in a NAV database with three companies (lets call these companies A, B and C) we will have three tables with customers. The table names will be A$Customer, B$Customer and C$Customer.

Now to my problem:

I wan't to write one report where I can choose company. I do not want to use a stored procedure. I want to use a function so I can use the function in select statements and join several functions to build up a report that needs data from several tables.

Is there some way to pass the table name or a part of the table name to a function that returns the content of the actual table? I know I can pass parameters that I can use in the where clause, but is it possible to do it with the table name. Or is there any other way to solve this.

All ideas are welcome. Thanks.

View 1 Replies View Related

Pass Table As A Parameter To A Function

Jul 25, 2007

Hi Friends,Is it possible to pass a table as a parameter to a funtion.whos function declaration would look some thing like this....ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT)my problem is: i have to access a temporary table created in an SP ina functionALTER PROCEDURE MySPBEGIN....DECLARE @TmpTable TABLE(...)....TempFunction(@TmpTable)....ENDThanksArunDhaJ

View 12 Replies View Related

Function That Take A Table As Input Parameter

Feb 27, 2008

i want to make a function that will take a table as input parameter. this table will be the output of a stored procedure. while i were writing the function i have an error and when i read about it i found that i can not send a table as input parameter to a function till i create a new TYPE of this table with its columns and data types as UDT but i found that sql server 2005 does not support the type 'table'...
my question now is it possible technically to make this function? is it possible to write something like that :

SELECT dbo.MyFunction(exec dbo.MystoredProc)

and in my function i am using CLR-Integration as this :
create function MyFunction
(
@TempTable table
(
ContractID int,
ContractNumber nvarchar(20),
Name_En nvarchar(80),
Name_Ar nvarchar(80),
ContractAmount money,
CurrencyID nchar(3),
DateStart smalldatetime,
DateEnd smalldatetime,
Currency_En nvarchar(30),
Currency_Ar nvarchar(30)
)
)
returns table( ContractNumber nvarchar(20),
Name_En nvarchar(80),
Name_Ar nvarchar(80),
ContractAmount decimal,
Currency_En nvarchar(30),
Currency_Ar nvarchar(30),
[Year] int,
[Month] int,
DomesticAmount decimal
)
as external name [AssemblyName].[PathOfTheFunctionInTheAssembly].[FunctionNameInAssembly]

please help me in this code as i need it urgently...
thanks in advance,
best regards,
Moustafa

View 9 Replies View Related

Transact SQL :: Passing Table Parameter To A Function

Nov 3, 2015

I have a function which accepts table parmeter. i have created a view and i need to use this function.

How can i do it. how can i pass dim table into the @table variable

select * from dim cross apply fnc_user(@table variable)

View 4 Replies View Related

Using A Scalar Valued Function As A Parameter Of A Table Valued Function?

Feb 1, 2006

Ok, I'm pretty knowledgable about T-SQL, but I've hit something that seems should work, but just doesn't...
I'm writing a stored procedure that needs to use the primary key fields of a table that is being passed to me so that I can generate what will most likely be a dynamically generated SQL statement and then execute it.
So the first thing I do, is I need to grab the primary key fields of the table.  I'd rather not go down to the base system tables since we may (hopefully) upgrade this one SQL 2000 machine to 2005 fairly soon, so I poke around, and find sp_pkeys in the master table.  Great.  I pass in the table name, and sure enough, it comes back with a record set, 1 row per column.  That's exactly what I need.
Umm... This is the part where I'm at a loss.  The stored procedure outputs the resultset as a resultset (Not as an output param).  Now I want to use that list in my stored procedure, thinking that if the base tables change, Microsoft will change the stored procedure accordingly, so even after a version upgrade my stuff SHOULD still work.  But... How do I use the resultset from the stored procedure?  You can't reference it like a table-valued function, nor can you 'capture' the resultset for use using the  syntax like:
DECLARE @table table@table=EXEC sp_pkeys MyTable
That of course just returns you the RETURN_VALUE instead of the resultset it output.  Ugh.  Ok, so I finally decide to just bite the bullet, and I grab the code from sp_pkeys and make my own little function called fn_pkeys.  Since I might also want to be able to 'force' the primary keys (Maybe the table doesn't really have one, but logically it does), I decide it'll pass back a comma-delimited varchar of columns that make up the primary key.  Ok, I test it and it works great.
Now, I'm happily going along and building my routine, and realize, hey, I don't really want that in a comma-delimited varchar, I want to use it in one of my queries, and I have this nice little table-valued function I call split, that takes a comma-delimited varchar, and returns a table... So I preceed to try it out...
SELECT *FROM Split(fn_pkeys('MyTable'),DEFAULT)
Syntax Error.  Ugh.  Eventually, I even try:
SELECT *FROM Split(substring('abc,def',2,6),DEFAULT)
Syntax Error.
Hmm...What am I doing wrong here, or can't you use a scalar-valued function as a parameter into a table-valued function?
SELECT *FROM Split('bc,def',DEFAULT) works just fine.
So my questions are:
Is there any way to programmatically capture a resultset that is being output from a stored procedure for use in the stored procedure that called it?
Is there any way to pass a scalar-valued function as a parameter into a table-valued function?
Oh, this works as well as a work around, but I'm more interested in if there is a way without having to workaround:
DECLARE @tmp varchar(8000)
SET @tmp=(SELECT dbo.fn_pkeys('MyTable'))
SELECT *
FROM Split(@tmp,DEFAULT)

View 1 Replies View Related

Inline Table-valued Function With Multi-value Parameter

Jul 18, 2007

Hello everybody,

I need to create a function which takes a multi-value parameter. When I select more than one item, I get the error that I have too many arguments. Does anybody have a solution?

Or can I create a view and then do a "SELECT * FROM viewName WHERE columnName IN (@param)"?

Thanks in advance for your answers.

View 7 Replies View Related

Table-valued Function Does Not Accept Chinese Characters As Parameter

Nov 15, 2007

I have a table-valued function in mssql 2005 as below:
ALTER FUNCTION fn_test{   @test nvarchar(1000)}RETURNS@TEMP TABLE{   test nvarchar(1000)}ASBEGIN   INSERT INTO @TEMP   SELECT @test
   RETURNEND
Everytime, I passed in chinese character (@test), such as 測驗, the function will return ????.  What should I do for the table-valued function, so that the chinese character can be passed in?  Please help.
Note: I can search and get the chinese characters if I use stored procedures; and the columns in the tables can store chinese chararcters as well.   Only table-valued function is not working with the chinese characters.  Is it a bug from MSSQL 2005?
 
 

View 4 Replies View Related

SQL Server 2008 :: Table Valued Function Where Parameter Has Multiple Values

Jan 29, 2015

Is it possible to pass multiple values to a TVF, such as using an IN clause?

View 6 Replies View Related

Reporting Services :: SSRS Multi-Value Parameter Feed To Table Value Function

Jul 24, 2015

I have an SSRS report with several variables, some of which are multi-valued.  The main query that feeds the report uses some table value functions.  For example, the query looks something like this:

select tv1.a, tv1.b, tv2.x, tv2.y, tbl.m, tbl.n
from tableValueFunction1(@MultiValueParam) as tv1
inner join tableValueFunction2(@MultiValueParam) as tv2 on tv1.xxx = tv2.xxx
inner join regularTable as tbl on tv1.xxx = tbl.xxx

where tbl.abc in (@MultiValueParam).When I try to run this, I get an error saying that I'm feeding the wrong number of parameters into the table value functions.  I've fed multi-valued parameters to stored procedures before and used a splitter function to split out the comma separated values, so I was planning to do the same thing in this scenario.  However, this is different.  When I look at the query in SQL Profiler, it shows discrete values for the multi value parameter.  For example, the same query above looks like this when viewed through the profiler (using 1,2,3 as my multi-value selection):

select tv1.a, tv1.b, tv2.x, tv3.y, tbl.m, tbl.n
from tableValueFunction1(1,2,3) as tv1
inner join tableValueFunction2(1,2,3) as tv2 on tv1.xxx = tv2.xxx
inner join regularTable as tbl on tv1.xxx = tbl.xxx
where tbl.abc in (1,2,3)

In other words, SSRS isn't converting the multi-value parameter to a comma separated string, like it normally does.

View 2 Replies View Related

Function Call

Mar 28, 2006

can i make a function call from stored procedure

View 3 Replies View Related

Call A Function

Feb 26, 2008

Does anybody knows how to call a function from one VB source file to another VB source file??

I have create a MDI parent form, now i want to call the function of the child form from the parent form. Does anyone know this??

View 1 Replies View Related

Need Help Understanding A Call To A Sql Function

Feb 25, 2008

Can someone help me to understand a stored procedure I am learning about? At line 12 below, the code is calling a function named"ttg_sfGroupsByPartyId" I ran the function manually and it returns several rows/records from the query. So I am wondering? does a call to the function return a temporary table? And if so, is the temporary table named PartyId? If so, the logic seems strange to me because earlier they are using the name PartyId as a variable name that is passed in.
 
1  ALTER              PROCEDURE [dbo].[GetPortalSettings]2  (3     @PartyId    uniqueidentifier,45  AS6  SET NOCOUNT ON7  CREATE TABLE #Groups8  (PartyId uniqueidentifier)910 /* Cache list of groups user belongs in */11 INSERT INTO #Groups (PartyId)12 SELECT PartyId FROM ttg_sfGroupsByPartyId(@PartyId)

View 4 Replies View Related

Call Custom SQL Function In ASP.NET

May 9, 2006

I made an SQL function in MSSQL2000. This is a function that get's a calculated heat emission. When I run the Query in MSSQL2000 the function works. It calculates every emission for every row. When I call this SQL function in VS2005, it says it does not recognize the function. Does anyone know what this may cause? thank you. For the people who are bored, I added the SQL statement. The error is at the function

SELECT TOP 15 tbProducts.prod_code, tbProductProperties.prop_height, tbProductProperties.prop_length, tbProductProperties.prop_type, tbProductProperties.prop_default_emission, tbProductProperties.prop_weight, tbProductProperties.prop_water_volume, tbProductProperties.prop_n_value, GetHeatEmission(50,70,20,[prop_default_emission],[prop_n_value]) AS customEmission FROM tbProductClassification INNER JOIN tbProducts ON tbProductClassification.clprod_fk_prod_id = tbProducts.prod_id INNER JOIN tbProductProperties ON tbProducts.prod_id = tbProductProperties.prop_fk_prod_id WHERE (tbProductClassification.clprod_fk_class_id = 3327) AND (prop_height >= '030') AND (prop_height = '060') AND (prop_length

View 1 Replies View Related

SQL Server Call C++ Function?

Dec 11, 2001

Hi,

Does anyone know if/how SQL server can call a function in a C++ library?

Cheers,

Xiaobing

View 4 Replies View Related

Overload Function Call

Aug 1, 2006

Hi,

I want to write one function like that

dbo.function( number , 1 , 2 ) ,

but I would like to overload, and send char or number

dbo.function( number, 'abx' , ' xpto' ).

I would like to keep the same name, Can I do this? or Do I need to write to differents functions



thanks,

View 11 Replies View Related

Call Function For Inner Join

Aug 10, 2007



I have a procedure which has query
like Query 1.

Query 1

Select Clinetid
from clinet
inner join {


select centerid from GetChildCenter(@Centerid)
union
select centerid from getParentCenter(@Centerid)
} as Center c

on c.Centerid = client.Centerid


Query 2

declare @Center table ( centerid int)
insert into @Center

select centerid from getchildCenter(@Centerid) union all select centerid from getparentcenter(@Centerid)

Select Clinetid
from clinet
inner join @Center c on c.Centerid = client.Centerid





I just want to know which one is better performance wise..
because there is millions of rows for table center which is used by function getChildCenter() and GetparentCenter()

View 1 Replies View Related

How To Change The Value Of The Parameter When Call

Sep 24, 2007

Hi
I have below sql procedure
CREATE PROCEDURE Qty
@make as nvarchar(32)

AS
select department as category from tblproducts where department = @make
GO

Parameter (@make) will get the value from asp.net page

My Question: Is any possibilities to change the value of parameter when the procedure trigger. Examlpe like below

If @make = 'Sealed Lead Acid' then I need to pass parameter to the database as 'SLA'
elseIf @make = 'Photographic' then 'Multimedia'
elseif @make = 'cctv and accessories' then 'security'

and so on. I only have six categories. Please help

Advance Thanks

View 3 Replies View Related

SQL Server 2012 :: Set Default Parameter For Function Parameter?

Jan 13, 2014

I want to set the default parameters for a function. I;d like to set the date start date to current date and end date for the last 90 days. how to make this work?

Create Function HR.Equipment
(
@startdate Date =(Convert(Date,DATEADD(DAY,-1,GETDATE())),
@enddate Date = (Convert(Date,@StartDate-90)
)
RETURNS TABLE AS RETURN
(
SELECT
EquipID,
EmpName,
IssueDate
FROM HR.Equipment
WHERE IssueDate <=@StartDate and IssueDate >=@EndDate
)
GO

View 5 Replies View Related

Call Function From Stored Procedure

Jan 19, 2007

Hi All,
I'll admit that I'm not the greatest at stored procedure/functions but I want to learn as much as possible.  So I have two questions:
1) I had VS2005 autogenerate a sqldatasource that created Select/Insert/Update stored procedures.  When Updating a record and calling the stored procedure, I want to query another table (we'll call it tblBatchNo) that has only one record, Batchno.  I want to put that current batchno into the Update statement and update the record with the current batchno.  Can someone point me in the right direction?  Remember that I'm still a beginner on this subject.
2) Can someone provide any links to online tutorials on t-sql?
Thanks in advance.
Curtis

View 2 Replies View Related

Trying To Call A Function On A Weekly Timer

Sep 17, 2007

I'm not sure this is the place for this question, but not sure where else to go.  I've written asp.net  code to read from a sql server 2005 db and send out customized emails based on user info.Currently the process gets rolling by clicking a button in a web page.The client doesn't want to click a button, they want to run the email sender on a timer.How can I set up my function to run on a timer either in asp.net or more likely called from sql server? 

View 6 Replies View Related

How To Call A Function In Stored Procedure

Sep 12, 2012

How to call a sql function in stored procedure using Sqlserver 2008?

View 4 Replies View Related

How To Call A Userdefined Function Within A Stored

Aug 27, 2007

Hello All,
How do i call a user defined function from within a stored procedure,
I have created a simple function which takes firstname and lastname as parameters and returns the concatenated name string.
That part works.


declare @fullname varchar(400)
@fullName=getFullName(@firstname,@lastname)


As always thanks for all your input

View 4 Replies View Related

Call Store Procedure From Function

Nov 13, 2007

Hi,is there any method to call a store procedure into a function?ThanksFabio

View 1 Replies View Related

Can Delete 'dbo.' Schema When Call Function In SP

Nov 21, 2007

Hi:

We found the problem that when the SP call function,there must have 'dbo.' before the function.Does it necessarily?Can delete 'dbo.' schema when call function in SP?

View 1 Replies View Related

Trying To Call The Function A Web Service From Transact-SQL

Jun 2, 2006

I currently have the fllowing Stored Procedure. When I pass the the Url of the web service in the parameters, I'm having a sp_OAMethor read response failed error.

I don't know how to pass the parameter as well as the name of the function in the Web Service I'm calling. Maybe I'm all wrong here with this code too?

Thanks for any help.



ALTER PROCEDURE [dbo].[pTAPServiceWeb]

@sUrl varchar(200),

@response varchar(8000) out

AS

DECLARE @obj int

DECLARE @hr int

DECLARE @status int

DECLARE @msg varchar(255)

EXEC @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT

IF @hr < 0

BEGIN

RAISERROR('sp_OACreate MSXML2.ServerXMLHttp failed', 16, 1)

RETURN

END

EXEC @hr = sp_OAMethod @obj, 'Open', NULL, 'GET', @sUrl, false

IF @hr < 0

BEGIN

SET @msg = 'sp_OAMethod Open failed'

GOTO err

END

EXEC @hr = sp_OAMethod @obj, 'send'

IF @hr < 0

BEGIN

SET @msg = 'sp_OAMethod Send failed'

GOTO err

END

EXEC @hr = sp_OAGetProperty @obj, 'status', @status OUT

IF @hr < 0

BEGIN

SET @msg = 'sp_OAMethod read status failed'

GOTO err

END

-- IF @status <> 200

-- BEGIN

-- SET @msg = 'sp_OAMethod http status ' + str(@status)

-- GOTO err

-- END

EXEC @hr = sp_OAGetProperty @obj, 'responseText', @response OUT

IF @hr < 0

BEGIN

SET @msg = 'sp_OAMethod read response failed'

GOTO err

END

EXEC @hr = sp_OADestroy @obj

RETURN

err:

EXEC @hr = sp_OADestroy @obj

RAISERROR(@msg, 16, 1)

RETURN

GO

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved