Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

error when try a "cast" in a char(13) to get a varchar....

$
0
0

AVAB_Codigo it's a "char(13)", get me a error :

"Invalid operator for data type. Operator equals boolean AND, type equals varchar."

when i use a cast...  the error still appear,.....  what should i do ?

-- 1st attemp --------------------------------------------------------------------

  case when (SUBSTRING(AVAB_Codigo,5,1)='0') 
   then Right(AVAB_Codigo,6) 
   else (SUBSTRING(AVAB_Codigo,5,1) & Right(AVAB_Codigo,6)) 
  end as [UL/UE]

-- 2nd attempt ----------------------------------------------------------------------

  case when (SUBSTRING(cast(AVAB_Codigo as varchar(10)),5,1)='0') 
   then Right(cast(AVAB_Codigo as varchar(10)),6) 
   else (SUBSTRING(cast(AVAB_Codigo as varchar(10)),5,1) & Right(cast(AVAB_Codigo as varchar(10)),6)) 
  end as [UL/UE],


Viewing all articles
Browse latest Browse all 12890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>