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.
Author |
Topic |
KingCarlos
Yak Posting Veteran
74 Posts |
Posted - 2012-07-24 : 02:48:57
|
Hi there, I am building a simple trigger that is creating a future task when a current task is complete.All is good but I am having diffuclty with the primary key. The primary key (taskid) starts with _2 and then is 20 extra random number charaters. Any help with the SQL insert for a record to have random charaters is appreciated.thanks |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-24 : 03:57:16
|
SELECT REPLACE(STR(CAST(1000000000*RAND() AS INT), 12), ' ', '0') But still it is not recommended as Primary Key as though its random number, still could be duplicate.--------------------------http://connectsql.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-24 : 09:52:55
|
whats the purpose of putting this in a trigger? looks like a good candidate for sql agent job------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
KingCarlos
Yak Posting Veteran
74 Posts |
Posted - 2012-07-26 : 00:24:46
|
SELECT REPLACE(STR(CAST(1000000000*RAND() AS INT), 12), ' ', '0') I have tried to use the above code in the insert command but it does not work.Basically the trigger is looking for a record that has been completed and re create it with a new start and due date and a new task ID. Can the above be modified? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-26 : 10:09:34
|
quote: Originally posted by KingCarlos SELECT REPLACE(STR(CAST(1000000000*RAND() AS INT), 12), ' ', '0') I have tried to use the above code in the insert command but it does not work.Basically the trigger is looking for a record that has been completed and re create it with a new start and due date and a new task ID. Can the above be modified?
what do you mean by it doesnt work?are you getting some error?whats the datatype of target column where you're trying to put this value------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|