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
 General SQL Server Forums
 New to SQL Server Programming
 Which UDF to use

Author  Topic 

hotshot_21
Yak Posting Veteran

97 Posts

Posted - 2007-05-11 : 06:42:20
I have a UDF which calculates three values.And i want to insert these values into a table.Which UDF shud i use?
E.g
CREATE Function CFS(var1,....)
Returns float
AS
Begin
Declare
@Tot_Time_CFS float,
@Avg_WLPD_CFS float,
@Avg_OnDuty_Officer_CFS float

Now these 3 variables r calculate and i want to inser tthese three variable values into other table.how do i go about it,

nr
SQLTeam MVY

12543 Posts

Posted - 2007-05-11 : 06:48:45
Well that only returns one value so you are a bit stuck.
What are you actually trying to do? Best wuld be to not use a function but to code it in-line as that woud be much faster.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

hotshot_21
Yak Posting Veteran

97 Posts

Posted - 2007-05-11 : 06:52:10
i am calculating 3 values which are being calculated in a function.and i want these 3 values to be stored in a row in a table.so i want to create a function for that .how do i go abt it.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-05-11 : 06:55:23
Sounds like you want a table valued function

insert tbl
select t.val1, t.val2, t.val3
from dbo.myfunc(....) t


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-05-11 : 06:56:58
like this

create function dbo.test12(@col1 int, @col2 int, @col3 int)
returns @t table (c1 int, c2 int, c3 int)as
begin
insert @t
select @col1, @col1, @col1
return
End

declare @tt table(col1 int, col2 int, col3 int)
Insert @tt
select * from dbo.test12(12,13,14)
select * from @tt
Go to Top of Page
   

- Advertisement -