nutnut
asked on
SQL Derived Number
Hi,
In SQL
I have 2 int columns in the same table that need to be concatenated to produce a unique 14 digit number. Concatenating the 2 int's will produce a unique number everytime (as one of them is a primary key) but the issue is if the int's are large they may exceed the 14 digit requirement.
Hope you can help
nutnut
In SQL
I have 2 int columns in the same table that need to be concatenated to produce a unique 14 digit number. Concatenating the 2 int's will produce a unique number everytime (as one of them is a primary key) but the issue is if the int's are large they may exceed the 14 digit requirement.
Hope you can help
nutnut
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks but this may exceed the 14 digit requiremnt
spotted a problem
if you add
111 to 1111
you get the same as adding
1111 to 111
even if the first is unique, the combination may not be
how about
declare @ikey int;
declare @some_int int;
select @ikey = 100000, @some_int = 99;
select RIGHT('0000000000' + cast(@ikey as varchar(10)),10) + RIGHT('0000' + cast(@some_int as varchar(10)),4)
if you add
111 to 1111
you get the same as adding
1111 to 111
even if the first is unique, the combination may not be
how about
declare @ikey int;
declare @some_int int;
select @ikey = 100000, @some_int = 99;
select RIGHT('0000000000' + cast(@ikey as varchar(10)),10) + RIGHT('0000' + cast(@some_int as varchar(10)),4)
Open in new window