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

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top