Solved

Sequence Help

Posted on 2007-03-22
2
190 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now