mysql - Optional variables in an sql query string -


i automating excel , have string read input sheet variable1,2,3,4,5,6

i wish make them optional if left empty query executes usual

  select left(name, 5)    production.product      product.name 'variable1'   product.brand 'variable2'   prodcut.price > 'variable3'   prodcut.expirydate > 'variable4'   order productid; 

try this:

select left(name, 5)  production.product (product.name @variable1 or @variable1 null) , (product.brand @variable2 or @variable2 null) , (product.price > @variable3 or @variable3 null) , (product.expirydate > @variable4 or @variable4 null) order productid; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -