문제

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