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?
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

0
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
0
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

É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

0
Amour22015Author Commented:
Never Mind I worked it out thanks for helping.
0
Éric MoreauSenior .Net ConsultantCommented:
what was the issue?
0
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?
0
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.
0
É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

0

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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.