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. ^_^
3 則留言:
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. ^_^
發佈留言