Solved

function is not a recognized built-in function name.

Posted on 2014-10-13
6
275 Views
Last Modified: 2014-10-13
I am getting:

Msg 195, Level 15, State 10, Line 1
'fnHasOrders' is not a recognized built-in function name.

(using SQLEXPRESS12 apparently iif() is acceptable to use)

After creating
Create FUNCTION dbo.fnHasOrders
(
 -- the parameters for the function here
 @CustomerID   int
)
RETURNS  varchar(20)
AS
BEGIN

declare @response  varchar (20)

Select @response = iif(isnull(o.OrderID,0)=0,'','<-- has orders') 
From tblCustomers c left join tblOrders o 
on o.CustomerID = c.CustomerID Where c.CustomerID=@CustomerID

 -- Return the result of the function
 RETURN @response

End

Open in new window


FYI: This function shows up under Functions/Scalar-value function folder at SSMS



Select CustomerID, fnHasOrders(CustomerID) from tblCustomers
0
Comment
Question by:Mike Eghtebas
  • 3
  • 3
6 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40379133
add
        dbo.

select CustomerID, dbo.fnHasOrders(CustomerID) from tblCustomers
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40379146
My favorite expert!

Thanks for the hint. There is a followup question.

Jack Smith            <-- has orders
Robert Nissan           <-- has orders

I want to line up <-- has orders portions in:

       SQL.ExecQuery("SELECT CustomerID, FirstName + ' ' + LastName + '     ' +" &
                     " dbo.fnHasOrders (CustomerID) as CustName From tblCustomers")


by having variable number of blank spaces instead of just '     ' above.

brb
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40379151
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 48

Expert Comment

by:PortletPaul
ID: 40379211
:) you are too kind, but thank you!

Cheers, Paul
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40379213
btw: you can also use the SPACE() function

 SQL.ExecQuery("SELECT CustomerID, substring(FirstName + ' ' + LastName + space(50) ,1,50) +" &
                     " dbo.fnHasOrders (CustomerID) as CustName From tblCustomers")
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40379226
Appreciate the tip.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question