Question

How would I insert values from a table valued parameter into a table

as it is right now it doesnt work.

Which is the best way of doing this?

ALTER PROCEDURE [dbo].[SaveDomainObject]
@Fields dbo.TemplateFieldsAsSqlParameter READONLY

AS
BEGIN
INSERT INTO DomainObjectFields
    VALUES (@UniqueKeyDomainObjectField, @Fields.FieldName, @Fields.FieldValue,@DateCreated, @DateUpdated, @Fields.AllowDuplicates)     

 END

the compiler tells me I need to daclere the Scalar variable @Fields.

How would I dothis?

kind regards

Was it helpful?

Solution

You should think of the table value parameter as a table, so you simply insert into your table by SELECTING from the table value parameter. If you have other fields that aren't in the TVP, just add them into the SELECT as you would normally.

INSERT INTO DomainObjectFields(column list)
SELECT (column list) 
FROM TableFieldsAsSQLParameter
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top