Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: Using and in simple sql

    Originally i had:

    DELETE FROM #RptDetails WHERE StructureType <> @StructureType
    AND #RptDetails WHERE #RptDetails.TraderId <> @TraderId OR #RptDetails.TraderId is null


    But it didnt delete the structure types i changed to :
    DELETE FROM #RptDetails WHERE StructureType <> @StructureType --AND
    DELETE FROM #RptDetails WHERE #RptDetails.TraderId <> @TraderId OR #RptDetails.TraderId is null

    and it did, how do i format the 2nd sql into 1 statement and what was i doing wrong?

  2. #2
    Join Date
    Aug 2005
    Location
    D/FW, Texas, USA
    Posts
    78
    Based on your first statement, I would assume something like this:
    Code:
    DELETE FROM #RptDetails
    WHERE StructureType <> @StructureType
    AND (#RptDetails.TraderId <> @TraderId OR #RptDetails.TraderId is null)
    However, running as two separate statements, you essientially get an "OR" instead of an "AND" for the second part of the where clause.
    Code:
    DELETE FROM #RptDetails
    WHERE StructureType <> @StructureType
    OR (#RptDetails.TraderId <> @TraderId OR #RptDetails.TraderId is null)
    The second method could delete more records because it doesn't require both parts of the statement to be true, so it all depends on what you're really looking for.
    --wayne
    SELECT * FROM Users WHERE Clue>0
    0 rows returned

Posting Permissions

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