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
 General SQL Server Forums
 New to SQL Server Programming
 Generating/updating unique random #'s in a column

Author  Topic 

MattGLoomis
Starting Member

2 Posts

Posted - 2012-01-11 : 17:08:21
We're a manufacturing company running SQL Server 2008 R2, and I have a SQL Table [FSDBGL.dbo.Mfg_ITMMAST] that holds information for every item we have. This includes columns for ItemNumber, ItemUPC, and ItemStatus. Some of the data in the ItemUPC column is empty for required items.

What I need to do, is assign/insert a random unique barcode number (that isn't already taken) inside of the [ItemUPC] column. The number needs to be 12 digits long, and be preceded with "601040xxxxxx", randomizing only the last 6 digits. This does not have to be done on every row for every item number.

-- Check/update only the [ItemNumber]'s (1xxxx-01 and between 40000-01 - 59999-01) (the -01 at the end could also be a -02)

I need to ignore/exclude the following column attributes from getting a number:
-- ItemStatus (only if it's set at 'O' for Obsolete)
-- ItemUPC (if it already has a barcode number)

I would like to customize a SQL query for this that I can populate the cells now, and implement into a nightly process to update any newly-created Item#'s as well.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-12 : 00:01:06
see below
http://weblogs.sqlteam.com/jeffs/archive/2004/11/22/2927.aspx

for the nightly process, create a sql server agent job with schedule set at night to execute the above logic based on your conditions

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

Go to Top of Page

MattGLoomis
Starting Member

2 Posts

Posted - 2012-01-12 : 11:11:30
That helps for setting up the random generation of numbers (including a range), however I still need to isolate the function to operate only on the required data (ie. only the 10,000 range and 40-50,000 range, as well as filtering out the obsolete products)

<researching like a mo-fo>
Have to have this in place by end-of-day :/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-12 : 12:28:20
for that you just need to add a where condition based on your logic

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

Go to Top of Page
   

- Advertisement -