0

I am attempting to create a table valued parameter for input into an MS SQL Server stored proc. My create statement:

CREATE TYPE dbo.tvt_AbusedBy AS TABLE  
( Assessment_Behavorial_AbusedID int, Assessment_BehavorialID int,
  Ref_Abuse_TypeID int, Abuser_Name varchar(50), GenderID int,
  Relationship_TypeID int, Age int)  

When attempting to add as a parameter into the proc:

CREATE PROCEDURE [dbo].[qryAddUpdateMultipletblAssessment_Behavorial_Abused] 
@prm_Assessment_Abused AS dbo.tvt_AbusedBy READONLY,

I get an error reading "The parameter @prm_Assessment_Abused cannot be declared READONLY since it is not a table valued parameter".

It does not seem to recognize it as a table valued parameter.

If I remote the READONLY stipulation, it gives me an error "Parameter or variable @prm_Assessment_Abused has an invalid type.

Must be an issue with how I am attempting to create the table valued parameter type.

Any ideas?

2
  • 1
    Try taking out AS in the parameter declaration. Commented Nov 28, 2018 at 14:47
  • remove dbo. from table value paramneter name Commented Nov 28, 2018 at 15:32

2 Answers 2

2

Don't use AS when adding parameters in a stored procedure declaration:

CREATE PROCEDURE [dbo].[qryAddUpdateMultipletblAssessment_Behavorial_Abused] 
  @prm_Assessment_Abused dbo.tvt_AbusedBy READONLY
Sign up to request clarification or add additional context in comments.

Comments

0

From MS documentation - https://learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql?view=sql-server-2017 You don't need AS before parameters, use it afters parameters declaration.

Example from link (a little edited):

CREATE PROCEDURE dbo.usp_add_kitchen 
@dept_id int, @kitchen_count int NOT NULL  
AS  
BEGIN
  UPDATE dbo.Departments  
  SET kitchen_count = ISNULL(kitchen_count, 0) + @kitchen_count  
  WHERE id = @dept_id  
END;  
GO  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.