Quick seelct query record count

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I need to check if a record exists (or not) in a table for a particular id.
Is there a quick way to do this (like ms access dlookup function or
similar)?

Thanks

Regards
 
In a multiuser DBMS application, you can indeed check to see if an ID exists
but it won't guarantee that the ID will or will not exist a millisecond
later as others add and remove rows in the target table(s).

SELECT IDWanted FROM MyTable WHERE ID = IDWanted

What problem are you trying to solve?

--
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest books:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition) and
Hitchhiker's Guide to SQL Server 2005 Compact Edition
 
Just need to copy records from one table to another but one at a time at
user request. So if the id (hence record) exists record is not copied
otherwise it is copied.

Thanks

Regards
 
Just need to copy records from one table to another but one at a time at
user request. So if the id (hence record) exists record is not copied
otherwise it is copied.

I would use a join or subselect query to move the data from one table to
another. Checking each row and copying can be very very slow if a large
amount of data need to be moved.
 
John said:
Just need to copy records from one table to another but one at a time at
user request. So if the id (hence record) exists record is not copied
otherwise it is copied.

Make an insert from a select, make a left join in the select against the
destination table and make a condition so that the select only returns
anything if the record doesn't exist in the destination table.

Example:

insert into Dest (A, B)
select s.A, s.B
from Source s
left join Dest d on d.SomeId = s.SomeId
where s.SomeField = Something and d.SomeId is null
 
Back
Top