Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Updae a table based on random numbers

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2002-05-11 : 11:07:01
Is it possible to write an T-SQL string that goes out and looks at a table and does two separate things, depending on the information in the table. One would to be to just leave it alone if cretin criteria where not meat and if that criteria was meat it would update the table based on the outcome of a random number 1-10?

Table Name: PrivetINFO
Column the script looks at to determine to leave it alone or run the Random Number part: CDoing
If that column has "On Snake Way" then it would then look at the column "Other" for "Completed Snake Way 1/3 or 2/3 or 3/3" and the column "TravelTime" is equals to "Other"'s /3 number then do nothing else it would change "Cdoing" to training and "Location" (in table playerINFO) to "PFIL, Main" on an even number, on an odd number it just changes "TravilTime" to the next /3 number. If that number was 3/3 and the random number was odd then "Cdoing" is changed to training and "Location" (in playerinfo) is changed to "King Kaio's,Main"

I know it is really complicated but if you don't understand something or have questions please ask me. I really want to be able to do this (and more things like it)

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2002-05-11 : 11:22:18
1. To only update certain rows, use a WHERE clause in your UPDATE statement :

UPDATE table
SET field1=2
WHERE field2=3

2. To allow for different values to be inserted based on a criteria, use a CASE statement:

UPDATE table
SET field1 = CASE WHEN field2=3 THEN 4 WHEN field4=5 THEN 5 ELSE 1 END

I hope this answer your question

Tim

Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2002-05-11 : 12:26:20
I know how to do the updating but I don't know how to do it based on a Random Number generated by either the script or the server.

Go to Top of Page
   

- Advertisement -