Solved

Sequence Help

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to count the amount of days from a date in the past 2 46
Need help creating a stored procedure 4 57
Stored procedure 4 32
SQL Agent Timeout 5 48
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now