Multiple "WHERE" statements in SQL depending on number of records retrieved
I guess this can be done in a stored Proc, but anybody any idea if and how to create a cfquery that has multiple WHERE statements based on the number of records?
Right now I have a query that runs, and gets 4 random records, based on criteria "A" defined in the WHERE statement, now if it only gets 1 record, I hit the dbase again, retrieving the same columns, but with a different clause in the WHERE, and so on, 4 times until I end up with my set of records.
It would be better if I had a little logic in the SQL so that it would say, find 4 random records, and if there are only 1, then run with this WHERE and if I still don't have a total of 4 (or whatever I set it to), then use this where and so on and so on
Btw I am using MS SQL2008
Thanks
Mark
