SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help With a Primary Key Record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

KingCarlos
Yak Posting Veteran

Australia
64 Posts

Posted - 07/24/2012 :  02:48:57  Show Profile  Reply with Quote
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

Pakistan
864 Posts

Posted - 07/24/2012 :  03:57:16  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
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/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48064 Posts

Posted - 07/24/2012 :  09:52:55  Show Profile  Reply with Quote
whats the purpose of putting this in a trigger? looks like a good candidate for sql agent job

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

KingCarlos
Yak Posting Veteran

Australia
64 Posts

Posted - 07/26/2012 :  00:24:46  Show Profile  Reply with Quote
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?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48064 Posts

Posted - 07/26/2012 :  10:09:34  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000