Thank you very much guys for all your support Hi everyoneI have two below datacolumns 'code'- varchar 255 (Unique number) data : chr456Umx'Packs'- integer data : 6Is it posible to generate 13 digit number using the above two columns,The reason is if I run the procedure I will get same 13 digit all the time depending on the above two colums below is the sample procedure I am usingCREATE PROCEDURE nvarchar(255)ASSelect code as sku, PdtBarCode as ,'EAN' as ,-generate 13 digit number make+' '+model+' ' +', Price for '+cast(NumPacks as varchar(8)) +' '+'Packs' as title,make as manufacturer,'from tablenamewhere. This is smaller SELECT RIGHT(CAST(CAST(NEWID() AS VARBINARY(36)) AS BIGINT), 13)However, this is not guaranteed to be unique.Īnother way of doing it select floor(rand()* 10000000000000)but column u have said cannot be int,it should be of type bigint With valid check digit? SELECT dbo.fnGetLuhn(CONVERT(VARCHAR, CURRENT_TIMESTAMP, 112) + RIGHT(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(36), NEWID()), 'A', ''), 'B', ''), 'C', ''), 'D', ''), 'E', ''), 'F', ''), '-', '') + REPLACE(CONVERT(VARCHAR, CURRENT_TIMESTAMP, 114), ':', '') + CONVERT(VARCHAR, CONVERT(VARCHAR, 12)) For example I have column name 'Packs' - int. So could please give me some sample code. ![]() I am about to generate this number (13) for 700 rowsThanks Is it posible to do in the select statment in sql procedure. But I don't want to create any table or insert. Add any two ledaing digits, maybe '55' to the IDENTITY e this code CREATE TABLE dbo.Test ( RowID INT IDENTITY(0, 1) PRIMARY KEY CLUSTERED, Dummy TINYINT, EAN13 AS dbo.fnGetLuhn('55' + RIGHT('000000000000' + CONVERT(VARCHAR, RowID), 10)) )select * from testinsert test (dummy) values (null)select * from testdrop table testwith the help of this function here Since last digit is a check digit, you only need 12 characters.An INT is 10 characters. It is not random, but it is unique.How many unique numbers do you want?What are you using the barcode for? I need to create UNIQUE random 13 digit number to use for barcode.How do I generate 13 digit UNIQUE random in sql procedure?Advance thanks ![]() ![]() How to generate random UNIQUE 13 digit number? We've got lots of great SQL ServerĮxperts to answer whatever question you can come up with.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |