Advertisement

11.10.2005 at 10:27AM PST, ID: 21626737
[x]
Attachment Details

find an unused number

Asked by g_johnson in MS SQL Server

Tags: number, what, find, first, unused

I am working with a table that has a "company code" column that is char (10), but is always a number, sometimes padded to the left, sometimes to the right and not otherwise formatted.

I need to return the first whole number (no matter what it might be) that is not in that column.

So if my company codes already used are '1','2','3','4','5','15','16','17','18' ...   I need to return 6 as a numeric

Is there a single query that can do this?

Start Free Trial
[+][-]11.10.2005 at 11:47AM PST, ID: 15268564

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.10.2005 at 12:43PM PST, ID: 15269070

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.10.2005 at 12:49PM PST, ID: 15269126

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.10.2005 at 12:49PM PST, ID: 15269130

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.10.2005 at 12:58PM PST, ID: 15269209

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.10.2005 at 01:00PM PST, ID: 15269240

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.11.2005 at 06:23AM PST, ID: 15273624

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: number, what, find, first, unused
Sign Up Now!
Solution Provided By: rdrunner
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.11.2005 at 06:25AM PST, ID: 15273638

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32