SELECT '_blank' AS TARGET dependant on a bit value

Posted on 2005-04-20
Last Modified: 2010-03-19

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,

Question by:Stoke
    LVL 26

    Expert Comment

    please try

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

    LVL 26

    Accepted Solution


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

    Expert Comment

    do select first to see if you get correct results
    select hrefTarget = case  bitfield
                                 when 1 then ' '
                                 when 0 then  hrefTarget

    if you do


    Update tablename
    set hrefTarget = case  bitfield
                                 when 1 then ' '
                                 when 0 then  hrefTarget
    from tablename

    Author Comment

    Spot on. Exactly what I wanted.
    Thank you Hilaire

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now