Stoke
asked on
SELECT '_blank' AS TARGET dependant on a bit value
Hi,
I'm stuck on a select statement
I have a bit field. If the bit has a value of 1 I would like to set target to equal '_blank' but if it is 0 then target equals '_self'
Something like:
SELECT IF bitField = 0 THEN '_self' AS hrefTarget
ELSE '_blank' AS hrefTarget
FROM site
What is the correct syntax to do something like this?
Thank you,
Stoke
I'm stuck on a select statement
I have a bit field. If the bit has a value of 1 I would like to set target to equal '_blank' but if it is 0 then target equals '_self'
Something like:
SELECT IF bitField = 0 THEN '_self' AS hrefTarget
ELSE '_blank' AS hrefTarget
FROM site
What is the correct syntax to do something like this?
Thank you,
Stoke
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do select first to see if you get correct results
select hrefTarget = case bitfield
when 1 then ' '
when 0 then hrefTarget
end
if you do
then
Update tablename
set hrefTarget = case bitfield
when 1 then ' '
when 0 then hrefTarget
end
from tablename
select hrefTarget = case bitfield
when 1 then ' '
when 0 then hrefTarget
end
if you do
then
Update tablename
set hrefTarget = case bitfield
when 1 then ' '
when 0 then hrefTarget
end
from tablename
ASKER
Spot on. Exactly what I wanted.
Thank you Hilaire
Thank you Hilaire
SELECT
CASE bitField
WHEN 0 THEN '_self' AS hrefTarget
ELSE '_blank' AS hrefTarget
END
FROM site