Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Sequence Help

Posted on 2007-03-22
2
194 Views
Last Modified: 2010-03-19
hello, i have a sequence number that I for the most part genorate myself, or the user can genorate for example 'a-3-b-ddm-axx' and if that number is in the databae, i want the database to see if that exsists, and if it does, to suggest another by using '-a' at the end of it if it is avalible.
0
Comment
Question by:wd006451
2 Comments
 
LVL 10

Accepted Solution

by:
ksaul earned 500 total points
ID: 18774608
declare @seq varchar(25)
set @seq = 'a-3-b-ddm-axx'

IF EXISTS (
  SELECT 1
  FROM YourTable
  WHERE SequenceField = @seq )
    IF EXISTS(
        SELECT 1
        FROM YourTable
        WHERE SequenceField LIKE @seq + '%' )
            SELECT @seq + '-'  + char(ascii(right(SequenceField,1))+ 1)
          FROM YourTable
      ELSE
            SELECT @seq + '-a'
ELSE
  SELECT @seq
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18774609
now what happens if it reaches 99,  -a99
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question