Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

UDF - What is causing this error?

Posted on 2016-09-19
1
Medium Priority
?
64 Views
Last Modified: 2016-09-20
I am getting this error when trying to compile.
Error:
Msg 102, Level 15, State 1, Procedure xTest, Line 43 [Batch Start Line 7]
Incorrect syntax near '@BookList'.


Function:
create FUNCTION [dbo].[xTest] 
(	

	@ShippingCost smallmoney = 0

)
RETURNS @BookList Table (
ISBN nvarhcar(13),
Title nvarchar(150),
Publisher nvarchar(150)
)


AS
Begin

With CTE As(

Select	g.ISBN, 
		g.Title,
		Case when bp.ISBN Is Null 
			Then g.Publisher Else bp.Publisher End 
													As Publisher,
		@ShippingCost								As ShippingCost
		

	From		tblGuides g
	Join		tblGuideHeader gh			On g.GuideNumber = gh.GuideNumber
	Join		tblPOSupplierItemList sl	On g.ISBN = sl.ISBN
	Left Join	tblBookPublisher bp			On bp.ISBN = g.ISBN

	where	gh.FinalShipDate < getDate()
		And
			(dbo.QtyLeft_Guide(g.GuideNumber, g.ISBN) > 0)
)
select  ISBN, Title, Publisher, ShippingCost
Into xxxx  from cte
 
 Select ISBN, Title, Publisher
 Into @BookList
 from xxxx Where ShippingCost = 1

return

End

Open in new window

0
Comment
Question by:Jess31
1 Comment
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 41805663
Replace it with INSERT
create FUNCTION [dbo].[xTest] 
(	

	@ShippingCost smallmoney = 0

)
RETURNS @BookList Table (
ISBN nvarhcar(13),
Title nvarchar(150),
Publisher nvarchar(150)
)


AS
Begin

With CTE As(

Select	g.ISBN, 
		g.Title,
		Case when bp.ISBN Is Null 
			Then g.Publisher Else bp.Publisher End 
													As Publisher,
		@ShippingCost								As ShippingCost
		

	From		tblGuides g
	Join		tblGuideHeader gh			On g.GuideNumber = gh.GuideNumber
	Join		tblPOSupplierItemList sl	On g.ISBN = sl.ISBN
	Left Join	tblBookPublisher bp			On bp.ISBN = g.ISBN

	where	gh.FinalShipDate < getDate()
		And
			(dbo.QtyLeft_Guide(g.GuideNumber, g.ISBN) > 0)
)
select  ISBN, Title, Publisher, ShippingCost
Into xxxx  from cte
 
 INSERT @BookList
 Select ISBN, Title, Publisher
 from xxxx Where ShippingCost = 1

return

End

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

916 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