473,416 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

coming up with a routine

hi

I have a DB which receive tickets in secuence 1,2,3,4,5.... I want to
create an routine that can detect if a ticket is missing so I just need to
detect if the secuence is broken (1,2,3,5... 4 is missing)

I want to create a good routine and I can only thing about a for loop with
IF THEN inside

Any one have an idea?

Can I do it with an Store procedure insted a C# code?

--
Kenny M.
Nov 19 '05 #1
2 1040
Hi Kenny,

I would instead have my table use an identity field for the ticket number
that auto-increments by 1. This way you would never have a number missing
from the sequence. Also in the table create a field for a flag as to
whether a ticket was cancelled or something. Then you can do a quick query
for all non-valid tickets just by checking this field. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Kenny M." <Ke****@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
hi

I have a DB which receive tickets in secuence 1,2,3,4,5.... I want to
create an routine that can detect if a ticket is missing so I just need to
detect if the secuence is broken (1,2,3,5... 4 is missing)

I want to create a good routine and I can only thing about a for loop with
IF THEN inside

Any one have an idea?

Can I do it with an Store procedure insted a C# code?

--
Kenny M.

Nov 19 '05 #2
Kenny... The first question is Is it worth optimizing this step? If the
answer is
yes, then you could possibly speed up the processing by returning a
sorted
sequence and writing your own algorithm doing a binary search looking
for
row number > ticket number where row number and ticket number are one
based.

This begs the question if your DB truly is guaranteed to create a
sequence.
Identity does _not_ quarantee a valid sequence. "The value automatically
produced with the Identity .... is not guaranteed to be consecutive. For
efficiency, a value is considered used as soon as it is presented to a
client."

So if a client starts an INSERT and then rolls back on error the number
is
_lost_ and a gap appears. If you want a consecutive sequence consider a
"next_number" table.

As for SQL.
http://www.developersdex.com/gurus/articles/115.asp
http://www.nigelrivett.net/FindGapsInSequence.html
http://www.tek-tips.com/faqs.cfm?fid=840

Finding gaps in an identity column sequence

Suppose a table has an identity column and gaps exist in the identity
sequence. Suppose you want to identify the gaps and fill them in. (I
don't
know why one would want to do this but we are just supposing. ) The
following T-SQL code will find the next gap in the sequence.

Create Procedure usp_FindNextPartID As

Declare @MinID int
Select @MinID = Min(PartID) From PartTable

If @MinID > 1
**Select MinID=1
Else
**Select MinID=min(a.PartId+1)
***From PartTable a Left Join PartTable b
*********On a.PartId+1=b.PartId
****Where b.PartNumber Is Null
Go
Regards,
Jeff
I have a DB which receive tickets in secuence 1,2,3,4,5.... I want to

create an routine that can detect if a ticket is missing so I just need
to
detect if the secuence is broken (1,2,3,5... 4 is missing)<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
5
by: peteh | last post by:
We are running DB2 PE (AIX) 8.1.5 and have built a SQL stored proc that uses the SNAPSHOT_APPL_INFO udf to return to the caller info about current db2 connections. The SP was created by a user...
1
by: Steemer | last post by:
Okay, I checked with usual suspects and I'm still frustrated. ..txt file, fixed width. About 88 fields of varying length. All text fields. It will only let me add seperators to about the 410th...
6
by: os2 | last post by:
hi i would like to try to reduce global variable for a program... i get a value from getenv... after this value will never change... i tried this code: void readRtuConfig(char *local_dir_led)...
11
by: Glen Wolinsky | last post by:
This is my first attempt as asynchronous processing. I have created a small test app as proof of concept, but I am having one proglem. In the example (code listed below), my callback routine has...
1
by: D. Shane Fowlkes | last post by:
I have a form in which clicking the submit button calls a "SaveData" sub rountine I wrote. The SaveData rountine inserts data from the form into a table and grabs the ID of the newly inserted...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
1
by: leeanngriego | last post by:
I have a client who has asked me to find him some solid up and coming embedded engineers. 2 to 3 years expereince with Embedded Linux, VxWorks, Nucleus or any other RTOS who has working in L2/L3...
4
by: Steve Swift | last post by:
I've asked this before, and last time the answer was "not possible". Maybe some more clever people are hanging around this time: Is there a way to trigger a routine when a page gets the "focus"?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.