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)
 Fetching MAX()-Values From Inside an UDF

Author  Topic 

sdiwi
Starting Member

27 Posts

Posted - 2005-10-18 : 04:10:23
Hi. I'm stuck at a little problem:
I try to write a UDF that gets 2 parameters

CREATE FUNCTION dbo.getNewID (@nameOfTable, @nameOfColumn)
....

What I want it todo is
SELECT MAX(@nameOfColumn) FROM @nameOfTable

That means I would have to build my query inside the function. But i cannot call sp_executesql to execute my query. The only way (i know) that could be working is writing a stored proc. but i cannot access it's return value from another proc/function (no temp tables!).

is there anything i could do?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-10-18 : 04:22:31
no.
the function has to be deterministic which is not when using dynamic sql inside.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-18 : 04:37:26
Use Stored Procedure instead of Function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -