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
 executing functions in QRY analyzer

Author  Topic 

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-02-27 : 08:20:49
Hi
How do i execute a function from qry analyzer ?
I have a simple function defined in the user functions section
and when i run this
exec Func_name(1,2)

it wont run ?

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'function'

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-27 : 08:21:56
Is it scalar function or Table valued function?

-- scalar function
select Func_name(1,2)

--tvf
select * from Func_name(1,2)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-27 : 08:25:26
Also qualify the function name with owner

Madhivanan

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

pazzy11
Posting Yak Master

145 Posts

Posted - 2008-02-27 : 08:37:50
[CODE]
CREATE FUNCTION Func2 (@p int, @s int, @c int, @sd int)
RETURNS TABLE
AS
RETURN (
SELECT distinct i.code, i.cam,i.p_id,i.s_id,i.start_moment,i.status,a.sub_id FROM inter i, ac a
WHERE status not in (3,9) AND
(
(i.p_id = @p AND i.s_id = @s AND i._id = @ca AND a.suid = @sid )

)
AND
i.c = a.in

select Func2(10,96,9,999)
[/CODE]

this wont work ...
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-02-27 : 08:40:13
as Madhi said... you need the owner too i.e. select * from dbo.Func2(10,96,9,999)


Em
Go to Top of Page
   

- Advertisement -