sql - within substring method how to use Isnull() -


in of columns have null value. can't achive other informations(my other columns) null value. use isnull. logged put isnull() in following code.

my code is

select top(10) 'insert jobs(budget) values('+      cast(substring(cast(r.budget varchar(50)), 0, patindex('%laks%', r.budget))*100000          + substring(cast(r.budget varchar(50)), patindex('%laks%', r.budget) + 4,          patindex('%thousands%', r.budget) - patindex('%laks%', r.budget) - 4)* 1000 varchar(50))+')'  requirementsdetailsfororganization r 

in above code, calculate salary in lakhs , thousands. wherever put isnull(), shows error.

suggest me come out of issue..

now think happening

you may have used patindex('%laks%', isnull(r.budget,''))

now patindex() returns zero if pattern not found. when search pattern '%laks%' inside empty string returned isnull() , value 0 returned causes error in substring() function , index out of range

one of solution filter out rows having null value or empty in budget column. can add len() function , check whether not equal 0 . see where condition added in query below.

select top(10) 'insert jobs(budget) values('+      cast(substring(cast(r.budget varchar(50)), 0, patindex('%laks%', r.budget))*100000          + substring(cast(r.budget varchar(50)), patindex('%laks%', r.budget) + 4,          patindex('%thousands%', r.budget) - patindex('%laks%', r.budget) - 4)* 1000 varchar(50))+')'  requirementsdetailsfororganization r len(r.budget)<>0 


values having null in budget column can insert default value zero


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -