Reputation: 115
If I have two parameter "parameterX" and "parameterY"
and I'll using "parameterX" and "parameterY" to commend sql snytax
like as
select * from test.test where
IF(parameterY!=0)
THEN test.test.'x'=parameterX AND test.test.'y'=parameterY
ELSE IF
test.test.'x'=parameterX
END IF
I know this's can't work But I want to know have a other way like it and it can work in mysql
Upvotes: 1
Views: 183
Reputation: 10812
Or easier (than @diehud's answer):
select * from test.test where
test.test.'x'=parameterX AND (test.test.'y'=parameterY OR parameterY=0)
Upvotes: 1
Reputation: 1326
I think dont need use IF ELSE
syntax
select * from test.test where
(parameterY!=0 and test.test.'x'=parameterX AND test.test.'y'=parameterY)
OR (parameterY = 0 and test.test.'x'=parameterX )
Upvotes: 1