I am building out some Data Protection answers for an update to our website and this one has me stumped in SQL Server 2008 R2:
I need to insert 'answers' to these questions for legacy customers. Here's an example statement that works for a single record:
INSERT INTO DataProtection
(
Id,
HolderCompanyId,
IssuerCompanyid,
AnswerEnum, --The answer (1,2,3) to the DP question
AnsweredDate,
ClientId, --This is the customer's unique ID
QuestionId --The ID of the question from a different table
)
VALUES
(
'9ee9455b-3ba5-440e-8329-c556ae8a1c7e',
1127,
1127,
10,
{ ts '2015-01-20 00:00:00' },
'12345',
'3'
);
How would I backbone off of this to insert thousands of rows (many times several rows per ClientID) for records that do not have an entry for each question (QuestionID)?
Example: Customer ID 12345 has answered '1' for Data Protection questions 1 and 2, but does not have an entry in the database for questions 3-6. There are many records like this.