I have select query which i need to order by ascending order. Column has varchar datatype so i need to convert it to int. My query is working fine but there is some situation when the user needs to enter such values
'121-1'
so it gives an error on select query
'Conversion failed when converting the varchar value '121-2' to data type int.'
So is there any solution to ignore this error even on entering such values(
'121-1'
). ? Following is my query
select ([Casetype] +'/'+ convert(varchar(50),CaseNo) +'/'+ convert(varchar(50),YEAR(GETDATE())) )as CaseNo ,
CaseNo_ID,
convert(varchar(20),[fileDate],103) as DateOfFilling,
DisrtictFrom,
tbl_RecordRequisition.CompName,
tbl_RecordRequisition.RespName,
CaseStage,
convert(varchar(20),NextDate,103) as NextDate,
tbl_RecordRequisition.Remarks
from tbl_RecordRequisition
order by left(CaseNo_ID,2) asc ,
right(CaseNo_ID,4) asc,
CAST((replace(replace(CaseNo_ID,left(CaseNo_ID,3),''),right(CaseNo_ID,5),'')) as int) asc
please help