Results 1 to 14 of 14

Thread: Need help with SQL statement ...

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Resolved Need help with SQL statement ...

    OK here goes ....


    I need to look in 2 files, say FileA and FileB for an item, say a lump of cheese.

    If I "drive" my SQL from FileA and "lump of cheese" does not exist, is there a way of making the SQL look in FileB ?

    At the moment if it can't find "lump of cheese" in File A it DOESN'T look in FileB (which as it happens is exactly where "lump of cheese" lives !)

    I've tried a left outer join, a right outer join, and nested select statements, but it seems to me that if the item your looking for doesn't exist in the file you are driving your statement from, then it stops right there and WON'T look in any other files regardless.

    Is that a correct assumption to make ?

    Am I making any sense ?

    Cheese haters need not apply !
    Last edited by TheBionicOrange; Oct 13th, 2004 at 09:51 AM.

  2. #2

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    Not really ... its too flippin big.

    Basically FileA and FileB are identical, only FileA holds "current" cheese and FileB holds "out of date cheese".

    The structure is the same for both, with field names prefixed with "FIN" for FileB.

    IS that any help at all ?

  4. #4
    Lively Member
    Join Date
    Sep 2004
    Posts
    96
    Stored Procedure or no?

    If so, then I'd use an If EXISTS on it:
    IF EXISTS (SELECT * FROM FileA WHERE Field = 'Lump OF Cheese')
    SELECT ... FROM FileA
    ELSE
    SELECT ... FROM FileB

  5. #5

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    No its NOT a stored procedure

    That would have been helpful though if it was

    but not

    no cheese for me it seems

  6. #6

  7. #7

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    I could look in FileA and then FileB, but I was trying to cut down the number of SQL statements I would need to execute.

    We are talking about potentially 70,000+ lumps of cheese here !

  8. #8

  9. #9

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    No .. its either finished or its not.

    Its OK I got it now (though best not to say where from )

    I needed the UNION command. That doesn't tell me WHICH file it came from, but thats not important, so long as I get a valid return thats fine.

    Cheers for your input though Woka

  10. #10

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    Resolved Re: Need help with SQL statement ...

    Originally posted by TheBionicOrange
    OK here goes ....


    I need to look in 2 files, say FileA and FileB for an item, say a lump of cheese.

    If I "drive" my SQL from FileA and "lump of cheese" does not exist, is there a way of making the SQL look in FileB ?

    At the moment if it can't find "lump of cheese" in File A it DOESN'T look in FileB (which as it happens is exactly where "lump of cheese" lives !)

    I've tried a left outer join, a right outer join, and nested select statements, but it seems to me that if the item your looking for doesn't exist in the file you are driving your statement from, then it stops right there and WON'T look in any other files regardless.

    Is that a correct assumption to make ?

    Am I making any sense ?

    Cheese haters need not apply !

  11. #11
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If you want to put the check icon on the thread you need to EDIT your first post, and add the check icon. So don't quote but edit the first post.
    Frans

  12. #12

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    Ha Ha !

    Oops ... and I was looking for my ost with a tick mark against it too.

    Sorry Dad

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Place an additional field with hardcoded values to tell you from which table the records came from

    SELECT "FROM A" AS SrcTable, field1, field2 FROM tableA WHERE blah blah
    UNION
    SELECT "FROM B", field1, field2 FROM tableB WHERE blah blah AND (SELECT COUNT(*) FROM tableA WHERE blah blah) = 0


    AND (SELECT COUNT(*) FROM tableA WHERE blah blah) = 0 is so you'll have TbaleB records if there are no records in tableA since records will only be returned if clause blah blah and AND (SELECT COUNT(*) FROM tableA WHERE blah blah) = 0 both return True

    Edit: Oh and you need to do FROM tableA IN databasepathinfo to b able to look in two files, I dont have a link to asite with the syntax here at home.

  14. #14
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by TheBionicOrange
    No .. its either finished or its not.

    Its OK I got it now (though best not to say where from )

    I needed the UNION command. That doesn't tell me WHICH file it came from, but thats not important, so long as I get a valid return thats fine.

    Cheers for your input though Woka
    That is exact WHAT i WAS GOING TO SUGGEST...damn caps.
    Should have said in my last post. Anyhooos, u have it now.

    woof

Posting Permissions

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



Click Here to Expand Forum to Full Width