Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    183

    Unanswered: Check for any record, first, top?

    I was just reading up on SELECT statements, and can't seem to find the specific information that I need.

    I have a table literally with terabytes of data, and what I want to do is check if there's any occurrances of the criteria I set. I don't want to return data, nor do I want the statements to run through all the rows/indexes.

    If there is just 1 row, I'm content. I want to make as little impact as possible, rather than doing a massive select. But does top 1 or first prevent this?

    e.g.
    Code:
     Select Top 1 From Orderlog Where datepart(yyyy, ordersentdate) = 2009 and ordertype = 12
    or similar using First.

    Thanks
    IT squid: networks, servers, firewalls, routers and I dabble a little with SQL-server and Access as well....

  2. #2
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    If Exists(
    Select 1 From Orderlog Where Year(ordersentdate) = 2009 and ordertype = 12
    )
    Print 'exists'
    Else
    print 'does not exist'


    will this help?
    Cheers....

    baburajv

  3. #3
    Join Date
    Oct 2005
    Posts
    183
    I don't know if that solves my problem, as it is as more a question of minimizing the performance impact of my query than actually returning anything more than a boolean confirmation.

    I suppose I can monitor my way through it and see a few diff. evals, I was just hoping that someone might know if TOP 1, First or anything similar was the preferred way of checking for records without starting a ton of index and record reads.
    IT squid: networks, servers, firewalls, routers and I dabble a little with SQL-server and Access as well....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •