0

Trying to insert multiple values in a table (as many as ID's from the SELECT result), but the select Id query returns more than 1 value (expected), hence the error.

INSERT INTO table1 (UserId, Date, ...)
VALUES
((SELECT Id from table2 WHERE ClientId = 26), GETDATE(), ...)

what would be the best approach for this?

1 Answer 1

1

I'm not sure how your columns line up. It looks like GETDATE() is inserting into Name. But if that's what you need, what about this? You could just do an INSERT SELECT without the VALUES.

INSERT INTO table1 (UserId, Name, ...)
SELECT Id, GETDATE(), ...
from table2 
WHERE ClientId = 26
Sign up to request clarification or add additional context in comments.

2 Comments

I've edited the example but yeah, this did the trick. Will marked as accepted once it lets me. thanks!
Glad to hear it.

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.