using TVP

I am trying to familiarize myself with the new TVP ability in server 2008
I have created a test file with the following creation codes
run in the order which I have placed them
The last is of course executing one of the SP

This is the error which I get
(0 row(s) affected)
Msg 208, Level 16, State 1, Procedure Table_Test, Line 5
Invalid object name 'newbudget'.

I know this is something simple but can not see it.

CREATE TABLE [dbo].[project](
	[project_no] [int] NOT NULL,
	[project_name] [nchar](10) NOT NULL,
	[budget] [float] NOT NULL
) ON [PRIMARY]

GO

CREATE TYPE [dbo].[newbudget] AS TABLE(
    [project_no] [int] NOT NULL,
	[budget] [float] NOT NULL,
	[rate] [int] NOT NULL

)
GO
CREATE   FUNCTION  [dbo].[nRate](@proj_no int)
	RETURNS int
AS
BEGIN
      DECLARE @rate int
      set @rate = case when (@proj_no % 2)=0 then 2 else 1 end
      RETURN @rate
END
GO

table AS newbudget READONLY)
AS
DECLARE @avgBudget FLOAT
SELECT @avgBudget = AVG(budget) FROM newbudget
PRINT 'The average budget is' + @avgBudget
GO

CREATE PROC Test_budget_call
AS
DECLARE @nbudget AS newbudget

INSERT INTO @nbudget ([project_no],[budget],[rate])

SELECT project_no,budget,dbo.nRate(project_no) AS rate

FROM project

EXEC Table_Test @nbudget

GO

EXEC Test_Budget_call
go

Open in new window

TagomAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
drop the AS keyword

DECLARE @nbudget newbudget
0
cyberkiwiCommented:
Hi there,

I pasted the whole thing into SSMS and it is saying that TABLE_Test does not exist.  It is not in the script above, can you please show what is in it?
0
TagomAuthor Commented:
gives the same error
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

cyberkiwiCommented:
Fixed script
CREATE TABLE [dbo].[project](
	[project_no] [int] NOT NULL,
	[project_name] [nchar](10) NOT NULL,
	[budget] [float] NOT NULL
) ON [PRIMARY]

GO

CREATE TYPE [dbo].[newbudget] AS TABLE(
    [project_no] [int] NOT NULL,
	[budget] [float] NOT NULL,
	[rate] [int] NOT NULL

)
GO
CREATE   FUNCTION  [dbo].[nRate](@proj_no int)
	RETURNS int
AS
BEGIN
      DECLARE @rate int
      set @rate = case when (@proj_no % 2)=0 then 2 else 1 end
      RETURN @rate
END
GO
create proc table_test (
@table AS newbudget READONLY)
AS
DECLARE @avgBudget FLOAT
SELECT @avgBudget = AVG(budget) FROM @table
PRINT 'The average budget is' + convert(varchar,@avgBudget)
GO

CREATE PROC Test_budget_call
AS
DECLARE @nbudget AS newbudget

INSERT INTO @nbudget ([project_no],[budget],[rate])

SELECT project_no,budget,dbo.nRate(project_no) AS rate

FROM project

EXEC Table_Test @nbudget

GO

EXEC Test_Budget_call
go

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TagomAuthor Commented:
sorry missed copying some of it
Here is that code

CREATE PROC Table_Test
(@ntable AS newbudget READONLY)
AS
DECLARE @avgBudget FLOAT
SELECT @avgBudget = AVG(budget) FROM newbudget
PRINT 'The average budget is' + @avgBudget
0
cyberkiwiCommented:
I guessed that :)

CREATE PROC Table_Test
(@ntable AS newbudget READONLY)
AS
DECLARE @avgBudget FLOAT
SELECT @avgBudget = AVG(budget) FROM @ntable  --- use the table var here
PRINT 'The average budget is' + convert(varchar, @avgBudget)   -- can't add into to text
0
TagomAuthor Commented:
Perfect
Thank you for taking the time to come back and highlight the mistakes....that helps in trying to understand how to manipulate these tables
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.