• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

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
0
nutnut
Asked:
nutnut
  • 2
1 Solution
 
sachinpatil10dCommented:
Try this

declare @Digit1 int = 20111010
declare @Digit2 int = 10000001

select convert(bigint,convert(nvarchar,@Digit1) + convert(nvarchar,@Digit2))

Open in new window

0
 
sachinpatil10dCommented:
The bigint data type is intended for use in cases where integer values might exceed the range supported by the int data type
0
 
nutnutAuthor Commented:
Thanks but this may exceed the 14 digit requiremnt
0
 
deightonprogCommented:
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)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now