sql server - Set A Variable From A Table -


If I want to set a variable to a field in a table, I usually

 < Code> SELECT @UserIdToUpdate = userId from #NewUsers  

In this case there will be many results and I just want the first one so I tried to do it but it failed and invalid syntax top

  SELECT @UserIdToUpdate = TOP 1 #NewUsers from user-plus  

If this is the case, then I would just be the first example without the top. I can obtain? I think this will only take the first record? I know that this seems like strange thing to do, but the command is in a loop, so it will select a record, do something with it, remove it and select the next one.

Alternatively,

  SELECT @UserIdToUpdate = (SELECT TOP  

It will work even when found in zero rows.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -