Solved

UDF - What is causing this error?

Posted on 2016-09-19
1
39 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 40

Accepted Solution

by:
Sharath earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now