473,396 Members | 2,039 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,396 software developers and data experts.

query-question: mark the Row that is selected in the query

Hi,

I have different VB.NET-applications that threat records from my table. To
be sure a record isn't threated by two applications at the same time, I want
to leave a mark in the record on the moment it is selected, so the other
applications know they don't have to use that record.

It should be something like this:
SELECT TOP 1 * FROM tblMyTable
WHERE Mark IS NULL
UPDATE Mark = 'Application1' WHERE RecID = TheIdOfTheRowThatWasJustSelected

Does anybody knwos how to do this?

Thanks a lot in advance!

Pieter
Nov 21 '05 #1
3 1122
You can use one statement:

UPDATE tblMyTable
SET Mark = 'Application1'
WHERE ID = (SELECT TOP 1 ID FROM tblMyTable WHERE Mark IS NULL)

Or you can use a transaction and an exclusivelock, so the row is locked
until you commit the transaction.

BEGIN TRANSACTION
SELECT TOP 1 * FROM tblMyTable WITH (XLOCK )
WHERE Mark IS NULL

UPDATE Mark = 'Application1' WHERE RecID = TheIdOfTheRowThatWasJustSelected
COMMIT TRANSACTION
--
Jacco Schalkwijk
SQL Server MVP
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP09.phx.gbl...
Hi,

I have different VB.NET-applications that threat records from my table. To
be sure a record isn't threated by two applications at the same time, I
want
to leave a mark in the record on the moment it is selected, so the other
applications know they don't have to use that record.

It should be something like this:
SELECT TOP 1 * FROM tblMyTable
WHERE Mark IS NULL
UPDATE Mark = 'Application1' WHERE RecID =
TheIdOfTheRowThatWasJustSelected

Does anybody knwos how to do this?

Thanks a lot in advance!

Pieter

Nov 21 '05 #2
You have not provided a lot of information, so I am going to ask a few
questions..
Are you trying to prevent the row from being updated in multiple places?
There are better methods available. I am sure that others will agree with
that statement: A couple of options that come to mind right away: SQL
Server has a timestamp column that can be used for this type of thing.
Another option: data comparison when you decide to update the row.

Why do you want to "lock" a record when it might not be updated? How do you
unlock the record if the user decides to abandon whatever it is that they
are doing?

--
Keith
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP09.phx.gbl...
Hi,

I have different VB.NET-applications that threat records from my table. To
be sure a record isn't threated by two applications at the same time, I want to leave a mark in the record on the moment it is selected, so the other
applications know they don't have to use that record.

It should be something like this:
SELECT TOP 1 * FROM tblMyTable
WHERE Mark IS NULL
UPDATE Mark = 'Application1' WHERE RecID = TheIdOfTheRowThatWasJustSelected
Does anybody knwos how to do this?

Thanks a lot in advance!

Pieter


Nov 21 '05 #3
Well, my application is liek this:

I habe a table that contains SMS, and several SMS-Modems that send the SMS.
But when 1 SMS-Modem is sending an SMS, it shouldn't been send by another
one at the same time.

So I don't really need advanced security-technologies or need to see if it
has been changed orn ot, but only need to be able to see if it's alreaddy
selected by another SMS Modem or not...

I hope this is enough explanation?

Thanks in advance,

Pieter

"Keith Kratochvil" <sq***********@comcast.net> wrote in message
news:uC*************@TK2MSFTNGP12.phx.gbl...
You have not provided a lot of information, so I am going to ask a few
questions..
Are you trying to prevent the row from being updated in multiple places?
There are better methods available. I am sure that others will agree with
that statement: A couple of options that come to mind right away: SQL
Server has a timestamp column that can be used for this type of thing.
Another option: data comparison when you decide to update the row.

Why do you want to "lock" a record when it might not be updated? How do you unlock the record if the user decides to abandon whatever it is that they
are doing?

--
Keith
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:es*************@TK2MSFTNGP09.phx.gbl...
Hi,

I have different VB.NET-applications that threat records from my table. To be sure a record isn't threated by two applications at the same time, I

want
to leave a mark in the record on the moment it is selected, so the other
applications know they don't have to use that record.

It should be something like this:
SELECT TOP 1 * FROM tblMyTable
WHERE Mark IS NULL
UPDATE Mark = 'Application1' WHERE RecID =

TheIdOfTheRowThatWasJustSelected

Does anybody knwos how to do this?

Thanks a lot in advance!

Pieter

Nov 21 '05 #4

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

Similar topics

6
by: Mark Reed | last post by:
Hi all, Please help. I have a table with 2 fields of which I am trying to change a select query into a delete query. the select query is: SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall...
1
by: ED | last post by:
I currently have an ODBC query that hits an Oracle database. I want to bring back records for a given month based on a job completion date in the Oracle database. I would like to have the user...
5
by: strauss.sean | last post by:
Hi! I am trying to import a query as a table from a MS Access database in a specified drive, path, and filename; my filenames and paths are being stored in a table for easy reconfiguration....
3
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while...
2
by: Chucara | last post by:
Hi, I'm trying to build a simple search in Access. I'll just give a simplified example, as I think I can solve the problem, if you can help me with this subproblem.. I have 2 listboxes -...
1
by: ljungers | last post by:
Hi and I hope that someone may have an answer for this, or an example of what I need to do. I have a Access database that a clerk will be entering a Order Number or Client Name or a Client City in a...
9
by: pandaking | last post by:
Hi there everyone, new here but after reading around it seems like I might hang about - so many helpful threads! I have a slight problem. This flying club near me has employed me to make them a...
2
by: Comandur | last post by:
Hi, I am trying to export an access query to excel. I have made use of transferspreadsheet command to achive this. However i have hardcoded the path and the filename in the VBA code. I am not sure...
7
Cshrek
by: Cshrek | last post by:
hi, i have a small query : ----------------------------------------------------------------------- SELECT * FROM Fares INNER JOIN Routes ON Fares.RouteID = Routes.RouteID WHERE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
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
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...
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,...

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.