VBdotnet2005
asked on
using If exists
Why am I keep getting error on if exists? sorry new to "if exists" , if exists, i just needs NewClient to say Yes, if not then No
select id,
clientid,
filename,
filedate ,
(if exists(select clientcode from clientname where clientcode = 'bofa')
'yes'
else
'No'
) as NewClient
from order_shipment
where order_name is null
order by filedate desc
select id,
clientid,
filename,
filedate ,
(if exists(select clientcode from clientname where clientcode = 'bofa')
'yes'
else
'No'
) as NewClient
from order_shipment
where order_name is null
order by filedate desc
Missed then
select id,
clientid,
filename,
filedate ,
case
when exists(select clientcode from clientname where clientcode = 'bofa') then
'yes'
else
'No'
end as NewClient
from order_shipment
where order_name is null
order by filedate desc
Though the syntax is correct, the query does not seem to be proper.
What is the relationship between clientname table and order_shipment?
Wouldn't be better if you found out if the client exists first before you run the query
eg
declare @Marker varchar(3)
if exists(select clientcode from clientname where clientcode = 'bofa')
@Marker = 'Yes'
else
@Marker = 'No'
select id,
clientid,
filename,
filedate ,
@Marker as NewClient
from order_shipment
where order_name is null
order by filedate desc
ASKER
Incorrect syntax near '@Marker'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
using this one
declare @Marker varchar(3)
if exists(select clientcode from clientname where clientcode = 'bofa')
@Marker = 'Yes'
else
@Marker = 'No'
select id,
clientid,
filename,
filedate ,
@Marker as NewClient
from order_shipment
where order_name is null
order by filedate desc
declare @Marker varchar(3)
if exists(select clientcode from clientname where clientcode = 'bofa')
@Marker = 'Yes'
else
@Marker = 'No'
select id,
clientid,
filename,
filedate ,
@Marker as NewClient
from order_shipment
where order_name is null
order by filedate desc
ASKER
this is good
select id,
clientid,
filename,
filedate ,
case
when exists(select clientcode from clientname where clientcode = 'bofa') then
'yes'
else
'No'
end as NewClient
from order_shipment
where order_name is null
order by filedate desc
select id,
clientid,
filename,
filedate ,
case
when exists(select clientcode from clientname where clientcode = 'bofa') then
'yes'
else
'No'
end as NewClient
from order_shipment
where order_name is null
order by filedate desc
ASKER
thank you very much
Open in new window