mysql - Searching datas with LIKE on result of CASE -


i want use sql syntax filter results of db outputs. firstly retrieve data want using case , when coditions. below...

            , case             when acc.account_type = 1 bnk.description1             when acc.account_type = 2 bnk.description2             when acc.account_type = 3 bnk.description3             end item 

and , want check syntax on outcomes.

         acc.record_del_flg = 0                , item '%%' 

there have been thrown mysql exception.. unknown column 'item'. question how ? in advances everybody. please me how figure out.

you can't use alias created on same level of where clause. hvae 2 choices,

one, wrap in subquery

select * (    select ....,           case             when acc.account_type = 1 bnk.description1             when acc.account_type = 2 bnk.description2             when acc.account_type = 3 bnk.description3             end item    tablename ) x x.item '%%' 

second, use whole expression on where clause,

where acc.record_del_flg = 0 ,        case when acc.account_type = 1 bnk.description1            when acc.account_type = 2 bnk.description2            when acc.account_type = 3 bnk.description3       end '%%' 

the reason why cannot use alias because in sql order of operation, where clause executes before select clause. here's list sql order of operation:

  • from clause
  • where clause
  • group clause
  • having clause
  • select clause
  • order clause

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -