Solved

UDF - What is causing this error?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested Case statement 4 39
SQL R 21 29
What is this datetime? 1 20
A trigger that informs the user when they have not entered the VAT number 6 22
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

820 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