Solved

UDF - What is causing this error?

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

705 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

18 Experts available now in Live!

Get 1:1 Help Now