I’m trying to do select * where column1 = % column2 %.
this is my query
select ticket_cp, id_con, raison_sociale, date, Type, RSP
from en_cours,
Base_Client
where Base_Client.Client like '%'+raison_sociale+ '%'
The error:
The data types varchar and text are incompatible in the add operator.
Advertisement
Answer
You can cast the text to a varchar(max):
select ticket_cp, id_con, raison_sociale, date, Type, RSP
from en_cours e
inner join base_Client b
on b.Client like '%'+ cast(e.raison_sociale as varchar(max)) + '%'
Or, if b.Client is a text too:
on cast(b.Client as varchar(max))
like '%'+ cast(e.raison_sociale as varchar(max)) + '%'
Notes (most of which already were commented):
textis deprecated; you want to usenvarchar(max)(ornvarchar(max)) insteadalways use explicit, standard joins (with the
onkeyword) instead of implicit, old-school joins (with commas in thefromclause)columns in the
selectclause should be qualified with the alias of the table they belong to in order to avoid any ambiguity