Solved

# Sequence Help

Posted on 2007-03-22
197 Views
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
Question by:wd006451
[X]
###### 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

LVL 10

Accepted Solution

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

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

## Featured Post

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
###### Suggested Courses
Course of the Month6 days, 23 hours left to enroll