Updating multiple records of two fields

I have a table called driver, and I want to update the driver position fields ('pos_x' and pos_y) with random numbers, and what I did was once select data from the table (to find out how many drivers I have) then refresh your position and then select the data again, is there any other way to do this?

0
c # sql-server
source share
2 answers

If you create a class to store information about the driver, you can exclude the last step (data selection again).

Stages:

1) Read the data in the list.

2) Update the values ​​in the list.

3) Write the data from the list to the database.

+2
source share

I want to update driver position fields (pos_x and pos_y) with random numbers

You can do this quite easily by simply using SQL.

UPDATE Person SET Pos_X = ABS(CHECKSUM(NEWID())) % 1000 , Pos_Y = ABS(CHECKSUM(NEWID())) % 1000 

As all this is done on the SQL server, this means that you will not carry data about the delivery of network overhead data back and forth. Of course, after that you will need to choose the result to work.

Why is ABS-CHECKSUM-NEWID? I tried this with the T-SQL RAND () function with less satisfactory results !

+1
source share

All Articles