It is good practice to always having a where clause in SQL statement. Especially for dynamic SQL construction: concat the where condition by several "and xxx", "and yyy", etc.
i remember one my colleague use if-case to compare each criteria which make coding is very long.
from that time i start to think can i build the sql dynamically to fulfill the input criteria. but i didn't use "where 1 = 1" at that time, i just erase the 'and' word first row of where clause, the idea is very useful.
now for complicated condition, a sql may be impossible to build or hard to build. we a tmp table in oracle and insert all hit record to the table. and then select all records out. ^_^
It is good practice to always having a where clause in SQL statement. Especially for dynamic SQL construction: concat the where condition by several "and xxx", "and yyy", etc.
回覆刪除easy for re-coding when the condition of the select statment needed to be changed
回覆刪除sean can u explain more detail on ur idea.
回覆刪除i remember one my colleague use if-case to compare each criteria which make coding is very long.
from that time i start to think can i build the sql dynamically to fulfill the input criteria. but i didn't use "where 1 = 1" at that time, i just erase the 'and' word first row of where clause, the idea is very useful.
now for complicated condition, a sql may be impossible to build or hard to build. we a tmp table in oracle and insert all hit record to the table. and then select all records out. ^_^