Khairy Abd el-Zaher Khairy Abd el-Zaher - 1 month ago 10
SQL Question

Conversion failed when converting the varchar value 'is_special_taken' to data type int

I don't know what is causing this error:


Conversion failed when converting the varchar value 'is_special_taken'to data type int.


The T-SQL code is:

select
O.id, O.title, O.type, O.points, O.icon, O.date,
COALESCE((select top 1 OAL.offer_id
from offer_accepted_log OAL
where O.id = OAL.offer_id
and OAL.customer_id = @customer_id
and O.type = 2), 0) as 'is_special_taken'
from
offer O
where
'is_special_taken' = 0
order by
O.[date] desc

Answer

Even though I voted to close, I want to point out a simpler way of expressing what I believe the intention of this query is:

select O.id, O.title, O.type, O.points, O.icon, O.date, 
from offer O
where not exists (select 1
                  from offer_accepted_log OAL
                  where O.id = OAL.offer_id and
                        OAL.customer_id = @customer_id and
                        O.type = 2
                 )
order by O.[date] desc;
Comments