473,587 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1052
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****@discuss ions.microsoft. com> wrote in message
news:9D******** *************** ***********@mic rosoft.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_numbe r" 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_FindNextPar tID As

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

If @MinID > 1
**Select MinID=1
Else
**Select MinID=min(a.Par tId+1)
***From PartTable a Left Join PartTable b
*********On a.PartId+1=b.Pa rtId
****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
5961
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 against a different table (that uses the LIKE predicate) but cannot get around the SQL0132 error . I have tried the hex notation after the LIKE such...
5
1817
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 id that belongs to the SYSADM_GROUP and the SYSADM_GROUP. This user can run the SP and get results. When a GRANT EXECUTE (by the definer/creator of...
1
2393
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 position but there are 420 positions. What's going on?
6
1350
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) { if(!(local_dir_led = getenv("LOCAL_DIR_LED"))) {
11
1755
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 two problems: 1. It runs TWICE; and 2. While it seems to update the web page controls, the results never show up on the page. I am using...
1
2008
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 record and stores it in a variable in the routine. The routine writes the data to the table just fine. But one of the last thing lines in my routine...
6
4080
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 the user wants all pages will produce 3 pages. I want to offer the user the ability to select via the print dialog that only pages 1 and 2 of it...
1
1648
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 networking. The object is to bring them on board and train in SAN/NAS switching, as long as they are solid C, Unix and Embedded programmers that have...
4
1147
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"? I'm thinking of when you switch to a page in a tabbed browser. Don't ask me what I'm going to do in such an event. It is no more interesting than...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.