Link to home
Start Free TrialLog in
Avatar of Stoke
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
Avatar of Hilaire
Hilaire
Flag of France image

please try

SELECT
CASE bitField
   WHEN 0 THEN '_self' AS hrefTarget
   ELSE '_blank' AS hrefTarget
END
FROM site

ASKER CERTIFIED SOLUTION
Avatar of Hilaire
Hilaire
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Stoke
Stoke

ASKER

Spot on. Exactly what I wanted.
Thank you Hilaire