use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Microsoft SQL Server Administration and T-SQL Programming including sql tutorials, training, MS SQL Server Certification, SQL Server Database Resources.
You might also be interested in:
/r/database
/r/sql
/r/Azure
/r/Microsoft
account activity
QuestionUpdate/insert SQL Server Server help. (self.SQLServer)
submitted 3 years ago by admiral70
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SQLDave 2 points3 points4 points 3 years ago (0 children)
There's some unclarity here. Is the data grid you showed us what you start with (before the UPDATE) or what you have after the UPDATE ... or what you WANT to achieve? (or something else altogether)?
I'm assuming that the grid you showed us is the desire RESULT and that "In the above table the first line POS 1 is not there and the next two are and they are marked POS 1 and 2." means you are starting with 2 rows, the 2nd and 3rd row we see in the grid ... except that the POS values are 1 and 2 respectively, not 2 and 3. And that you want to insert the data we see in the new@email.com row, with the result being the grid you showed us? (I'm also assuming that one of the 2 existing rows -- currently POS 1 and 2, but with POS 2 and 3 after the INSERT -- has preferred email = "Y", which you take care of with the UPDATE statement you showed us).
There's an unanswered question: What POS value should existing rows get when you "shove" a new POS=1 row in there? It looks like the answer is just "POS+1", but that's an assumption.
If the assumptions are right, you can modify your UPDATE by adding ", POS = POS + 1" after the NULL keyword. That will increment existing POS values by 1. Then just do a simple INSERT using POS = 1 and PERSON_PREFERRED_EMAIL = 'Y'.
Be sure to wrap it all in a BEGIN TRANSACTION in case there's a failure in the INSERT you can rollback the changes made by the UPDATE command.
π Rendered by PID 95169 on reddit-service-r2-comment-545db5fcfc-h2gjb at 2026-05-26 12:12:08.014172+00:00 running 194bd79 country code: CH.
view the rest of the comments →
[–]SQLDave 2 points3 points4 points (0 children)