Link to home
Start Free TrialLog in
Avatar of Tagom
Tagom

asked on

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

Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

drop the AS keyword

DECLARE @nbudget newbudget
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?
Avatar of Tagom
Tagom

ASKER

gives the same error
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tagom

ASKER

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
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
Avatar of Tagom

ASKER

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