[thelist] ASP, SQL, Recordsets, Best Practices

rudy r937 at interlog.com
Thu Mar 1 14:48:33 CST 2001


> When querying a unique field in a database, and the answer is
> either "yes a record exists" or "no record exists", is it necessary
> to still loop through the recordset?

hi michele

well, DUH  (no offence to you personally)

the idea that you might need to "loop" indicates a programming (action
oriented) approach to the problem

which is good, as you're dealing with ASP   <dons flame-retardant suit />

how about this --

    IF "yes a record exists"
           [ do something ]
    ELSE
           [ do something else, perhaps nothing ]



>... when there can only be one
> unique record (field doesn't allow duplicates) or no record at all.

presumably you want to do something with the fields for this particular
row?  if you don't need to use any of the fields, i.e. if you only need to
know *whether* a row exists, then you should be using

    select count(*) from [table] where [uniqueness]

you'll get back a 0 or some positive number, and you can build the IF
ELSE condition just by testing on zero

count(*) is a lot quicker for the database, too -- no rows to access


rudy.ca






More information about the thelist mailing list