TSQL - Stored Procedure Function has syntax error

Hi Experts,

I have this that I need to correct the syntax:
Select Distinct Contact2, IsKeyEmail, Entry, Address, FullName
FROM tblNAsCommunications Comm Join 
	tblNAsAffiliations Aff On Comm.Contact = Aff.Contact2 Join
	tblNAsContacts C On C.Contact = Aff.Contact2 Join 
	fncUtlFullAddress(Address, HTML) ON fncUtlFullAddress.Contact = C.Contact

Open in new window


I get "Invalid Object Name"
on:
fncUtlFullAddress

Please help and thanks...
Amour22015Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you are surely missing the schema name (dbo.) and the alias:
Select Distinct Contact2, IsKeyEmail, Entry, Address, FullName
FROM tblNAsCommunications Comm Join 
	tblNAsAffiliations Aff On Comm.Contact = Aff.Contact2 Join
	tblNAsContacts C On C.Contact = Aff.Contact2 Join 
	dbo.fncUtlFullAddress(Address, HTML) fnc ON fnc.Contact = C.Contact

Open in new window

Amour22015Author Commented:
But I still get the syntax error?

when I try to execute.

Do I have to have the parameters also included when I execute?

Thanks for helping
Scott PletcherSenior DBACommented:
You need to give it a table alias:

select Distinct Contact2, IsKeyEmail, Entry, Address, FullName
FROM tblNAsCommunications Comm Join
      tblNAsAffiliations Aff On Comm.Contact = Aff.Contact2 Join
      tblNAsContacts C On C.Contact = Aff.Contact2 Join
      dbo.fncUtlFullAddress(Address, HTML) AS fufa ON fufa.Contact = C.Contact
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Éric MoreauSenior .Net ConsultantCommented:
are you sure it is a "table-valued function"?

what is the result if you try:
select * from dbo.fncUtlFullAddress('Address', 'HTML')

Open in new window


and because it is a UDF taking arguments, you will need to use cross apply instead of join:
Select Distinct Contact2, IsKeyEmail, Entry, Address, FullName
FROM tblNAsCommunications Comm Join 
	tblNAsAffiliations Aff On Comm.Contact = Aff.Contact2 Join
	tblNAsContacts C On C.Contact = Aff.Contact2 
cross apply dbo.fncUtlFullAddress(Address, HTML) 

Open in new window

Amour22015Author Commented:
Never Mind I worked it out thanks for helping.
Éric MoreauSenior .Net ConsultantCommented:
what was the issue?
Amour22015Author Commented:
It is not a "table-valued function"

It is a "Scalar-valued function"  so it looks like I am doing that wrong also?
Amour22015Author Commented:
So when I do:
select * from dbo.fncUtlFullAddress('Address', 'HTML')

Open in new window

I get:
Msg 208, Level 16, State 3, Line 1
Invalid object name 'dbo.fncUtlFullAddress'

I thought it was correct but it is not
Please help and thanks.
Éric MoreauSenior .Net ConsultantCommented:
>>Never Mind I worked it out thanks for helping.

is it working or not?

If it is not a table-value function, you cannot join!

would that work:
Select Distinct Contact2, IsKeyEmail, Entry, Address, FullName, dbo.fncUtlFullAddress(Address, HTML) 
FROM tblNAsCommunications Comm Join 
	tblNAsAffiliations Aff On Comm.Contact = Aff.Contact2 Join
	tblNAsContacts C On C.Contact = Aff.Contact2 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amour22015Author Commented:
Great Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.