0

I have a table with columns:

StudentID
Value1
Value2
Value3

...and I have three queries, each one will come with the studentID and a value(1 to 3) fields

What I would like to do is to update this table, with parallel values, if a student exists then update the corresponding column if not, create a new row.

I'm working with SQL Server 2005

1
  • Is this homework? Ideally you would use the merge syntax, but that wasn't available until SQL Server 2008. Commented Sep 27, 2012 at 14:11

1 Answer 1

2

Write it like you just said it:

IF EXISTS(SELECT * FROM table WHERE StudentID = @StudentID)
BEGIN
--update
END
ELSE
BEGIN
--insert
END
Sign up to request clarification or add additional context in comments.

Comments

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.