sql - Some rows of Order by column is null. How to make Order by column optional on that situation -


i have prob in following select query.

select *  ".$table2." a,purpose_details b   b.purpose_code=a.purpose , purpose_code in(1,4,6,7,10)     , ((fromdt<='$frmdate'and todt>='$frmdate')           or (fromdt<='$frmdate' , todt='1111-11-11'))    ,  substr(a.appno,4,1)!=6   order purpose_priority,          cast(substr(a.case_no,12,4) int) ,cast(substr(a.case_no,4,1) int),          cast(substr(a.case_no,5,7) int),cast(substr(a.appno,12,4) int) ,          cast(substr(a.appno,4,1) int),cast(substr(a.appno,5,7) int)"; 

the problem rows in table2 may or may not have value of appno. (ie) appno value may null of rows.

due appno 1 among in order column particular code retuns invalid input error.

finally want select query arrange columns appno when appno value not null.

note: order clause rest of columns should applied on both situations.

pls me sort out. in advance.

order can definitly handle null values substr cannot. should replace

substr (col, ... 

with

case when col null null else substr (col, ... 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -