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
 Function Doubt

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2011-05-10 : 10:32:40
Hi ,

I have written a function which should return contact_id but instead it returns clarify_objid.

ALTER function [dbo].[fnGetMRMObj_ID]
(@Con_ObjID int)
RETURNS INT
AS
BEGIN
return (ISNULL((select min(contact_id)
from Contact
where clarify_objid = @Con_ObjID
),0))

END

Please advice what might be in correct to return the clarify_objid instead of contact_id..

Thanks,


Dp

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-05-10 : 11:04:33
Seems to work just fine. Did you test the function at all?
CREATE TABLE Contact (contact_id INT, clarify_objid INT)

INSERT Contact (contact_id, clarify_objid)
VALUES (1, 999)

CREATE function [dbo].[fnGetMRMObj_ID]
(@Con_ObjID int)
RETURNS INT
AS
BEGIN
return (ISNULL((select min(contact_id)
from Contact
where clarify_objid = @Con_ObjID
),0))
END


SELECT [dbo].[fnGetMRMObj_ID](999)

DROP FUNCTION [dbo].[fnGetMRMObj_ID]
DROP TABLE Contact
Go to Top of Page
   

- Advertisement -