-4

I am trying to below query if condition not working

SELECT SUM(quantity) as qty 
FROM hud_allotment 
where IF (dvn_cd='$q') and IF(to_dvn='$q');  

please advise me

Ullas
  • 11,450
  • 4
  • 33
  • 50
Sniper
  • 3
  • 4
  • Hi try this http://stackoverflow.com/questions/63447/how-do-you-perform-an-if-then-in-an-sql-select this is what you are looking for. – Arvind Mar 11 '15 at 07:42
  • 1
    Why `IF`? Why cant you give like `SELECT SUM(quantity) as qty FROM hud_allotment where dvn_cd='$q' and to_dvn='$q';` – Ullas Mar 11 '15 at 07:42
  • the dvn_cd or to_dvn any one value come so only i am asking if condition – Sniper Mar 11 '15 at 07:51

1 Answers1

0

You do not need if it could be done with where and

SELECT SUM(quantity) as qty 
FROM hud_allotment 
where dvn_cd='$q' and to_dvn='$q';  
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
  • the dvn_cd or to_dvn any one value come so only i am asking if condition – Sniper Mar 11 '15 at 08:05
  • Then change the condition to `where where dvn_cd='$q' or to_dvn='$q'; ` Better if you provide some sample data and expected output it would be better to understand. – Abhik Chakraborty Mar 11 '15 at 08:20