corner : SQLServer cached procedure does not splicing multi- criteria query SQL string ,
GHD Purple Butterfly 2011
splicing written
set @ sql = 'select * from table where 1 = 1'
whether (@ addDate namely not null)
set @ sql = @ sql + 'and addDate =' + @ addDate + ''
if (@ name ''and is not null)
set @ sql = @ sql + 'and name = '+ @ name +' '
exec (@ sql)
do not use multi- splicing conditions SQL query string solutions
The premier was written some code redundancy
if (@ addDate is not null) and (@ name '')
elect * from table where addDate = @ addDate and appoint = @ name
else if (@ addDate is not null) and (@ name ='')
select * from table where addDate = @ AddDate
another if (@ addDate is null) and (@ name '')
select * from table where and name = @ name
else if (@ addDate is null) and (@ name ='')
select * from table
The second was written
select * from table where (addDate = @ addDate or @ addDate is null) and (name = @ name or @ name ='')
The third was written
SELECT * FROM table where
addDate = CASE @ addDate IS NULL THEN addDate ELSE @ addDate END,
GHD IV Black Straighteners,
name = CASE @ name WHEN''THEN name ELSE @ name END