Like any other code, there are times when portions of your SQL queries need
to be re-used or duplicated. A common example is having a method that
returns a COUNT of a query based on some conditions, and having another
method that returns some rows from that query. For instance:

*** getCount() ***
SELECT 
    Count(OrderID) as OrderIDCount
FROM 
    OrderTable INNER JOIN 
    StatusTable ON (OrderTable.OrderID= StatusTable.OrderID)
WHERE 
    (whatever)

*** getRows() ***
SELECT TOP 50
   OrderID, StatusID
FROM 
    OrderTable INNER JOIN 
    StatusTable ON (OrderTable.OrderID= StatusTable.OrderID)
WHERE 
    (whatever)

In the preceding code, the FROM clause is repeated in both methods, as is
the WHERE clause. 

Now in a real-world complex app, that FROM would actually be 10-15 lines
long, and the WHERE could have hundreds of lines of complex logic based on
passed in arguments. Plus you may need not 2, but 5, 10, 20 methods using
the same FROM and/or WHERE and/or SELECT.

So my question is how do people handle this? If you had 15 methods with
complex WHERE and FROM clauses that are repeated intermittently, and then
something changes, it's an error-prone hassle to copy paste all the affected
sections.

Thoughts?

Baz




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:231101
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to