Hi All
I am calling a function from a stored procedure (the function is created
before the stored procedure). Both the stored procedure and the function are
created successfully (no syntax errors in the enterprise manager).
When I try to execute the stored procedure I get the message "Invalid object
name 'twuser.Proc_SelectTwinEntries'".
I can't find anything wrong, can anyone help?
Thanks in advance
Elie Grouchko
CREATE FUNCTION twuser.Proc_SelectTwinEntries(
@.twc_comment_subject int
) RETURNS TABLE
AS
RETURN (
SELECT
[twc_comment_twin]
FROM [twt_comment]
WHERE ([twc_comment_subject] = @.twc_comment_subject) AND ([twc_comment_twin]
IS NOT NULL)
)
CREATE PROCEDURE twuser.Proc_SelectTopForumCommentsOrderByDate
@.twc_comment_subject int
AS
SELECT TOP 5 * FROM [twt_comment]
WHERE ((([twc_comment_subject] = @.twc_comment_subject) AND ([twc_comment_id]
!= @.twc_comment_subject)) OR
([twc_comment_firstparent] IN
(twuser. Proc_SelectTwinEntries(@.twc_comment_subj
ect))))
AND ([twc_comment_state] = 2) AND [twc_comment_twin] IS NULL
ORDER BY [twc_comment_date] DESC
GOYou can only reference a table-valued UDF in the FROM clause. You could
change your IN subquery:
SELECT [twc_comment_twin]
FROM twuser. Proc_SelectTwinEntries(@.twc_comment_subj
ect)
but I don't see much point here. Why not just combine the logic of the
two queries?
David Portas
SQL Server MVP
--|||> ([twc_comment_firstparent] IN
> (twuser. Proc_SelectTwinEntries(@.twc_comment_subj
ect))))
([twc_comment_firstparent] IN
(select [twc_comment_twin] from
twuser. Proc_SelectTwinEntries(@.twc_comment_subj
ect))...
"Elie Grouchko" wrote:
> Hi All
> I am calling a function from a stored procedure (the function is created
> before the stored procedure). Both the stored procedure and the function a
re
> created successfully (no syntax errors in the enterprise manager).
> When I try to execute the stored procedure I get the message "Invalid obje
ct
> name 'twuser.Proc_SelectTwinEntries'".
> I can't find anything wrong, can anyone help?
> Thanks in advance
> Elie Grouchko
> CREATE FUNCTION twuser.Proc_SelectTwinEntries(
> @.twc_comment_subject int
> ) RETURNS TABLE
> AS
> RETURN (
> SELECT
> [twc_comment_twin]
> FROM [twt_comment]
> WHERE ([twc_comment_subject] = @.twc_comment_subject) AND ([twc_comment_twi
n]
> IS NOT NULL)
> )
> CREATE PROCEDURE twuser.Proc_SelectTopForumCommentsOrderByDate
> @.twc_comment_subject int
> AS
> SELECT TOP 5 * FROM [twt_comment]
> WHERE ((([twc_comment_subject] = @.twc_comment_subject) AND ([twc_comment_i
d]
> != @.twc_comment_subject)) OR
> ([twc_comment_firstparent] IN
> (twuser. Proc_SelectTwinEntries(@.twc_comment_subj
ect))))
> AND ([twc_comment_state] = 2) AND [twc_comment_twin] IS NULL
> ORDER BY [twc_comment_date] DESC
> GO
>
>
No comments:
Post a Comment