Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Passing Column value to UDF

Author  Topic 

anoopsinghal80
Starting Member

3 Posts

Posted - 2005-02-08 : 05:28:42
Dear All,

I want to pass a value of column to a User Defined Function which I am using in my query and the value will come from Query based on the result set.

Actually I am using a function returning table and using it in join with another table so when I pass the column value to it it givs me Incorrect Syntax.

Waitng for you response.

Regards
Anoop Singhal
Database Administrator
Advent Matrix Inc.
www.stonematrix.com

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-02-08 : 06:40:28
Post DDL & DML, the error message and expected results

Andy
Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2005-02-08 : 07:17:35
Hello!

You cannot use a table-valued function as you would a scalar function. Sounds as though that's what you are trying to do.

You can't do this (for obvious reasons if you think about it):

select t.t, t2.value
from t1 inner join dbo.func(t.t) t2 on t1.t=t2.t

You'll have to save the value you want to use in a variable first.

/Andraax
Go to Top of Page

anupkansal8
Starting Member

1 Post

Posted - 2005-02-08 : 08:14:00
TRY THIS


USE PUBS
GO
Create FUNCTION FN_SALES1 (@QTY FLOAT)
RETURNS TABLE AS
RETURN (SELECT * FROM SALES WHERE QTY >= @QTY)
GO
SELECT ST.STOR_NAME,SL.* FROM STORES ST JOIN dbo.FN_SALES1 (40) SL ON ST.STOR_ID=SL.STOR_ID


anup
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-02-08 : 08:56:58
Why are you using a UDF? Instead posting what you are trying to do and saying "it won't work!", show us what you have for data (small, revelant sample) and what you are trying to return with that data and why. I doubt you need (or want) to use a UDF.

- Jeff
Go to Top of Page
   

- Advertisement -