[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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
0
Stoke
Asked:
Stoke
  • 2
1 Solution
 
HilaireCommented:
please try

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

0
 
HilaireCommented:
Oops

SELECT
CASE bitField
   WHEN 0 THEN '_self'
   ELSE '_blank'
END AS hrefTarget
FROM site
0
 
JulianvaCommented:
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
0
 
StokeAuthor Commented:
Spot on. Exactly what I wanted.
Thank you Hilaire
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now