Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    17

    Unanswered: If a record exist then Y else N

    Hi

    I'm trying to write a query in Sybase

    SELECT
    bs.b_beneficiary_id
    ,CASE
    WHEN EXISTS (SELECT 1
    FROM dss.fq_medicineauth
    where source = 'B')
    THEN 'Y'
    ELSE 'N'
    END[Chronic_Indicator]
    FROM dss.dq_beneficiary_snapshot

    I get an error that this is not supported, how do I write a query to get either Y or N on that field.

  2. #2
    Join Date
    Feb 2012
    Posts
    133
    you need to write the CASE line somewhat similar below command

    case when exists (select * from t2 where t1.id = t2.id) then 1 else 0 end

  3. #3
    Join Date
    Feb 2012
    Location
    Pune
    Posts
    11
    What error its throwing -- Query looks fine and it should run -- check on alias name

    SELECT
    b_beneficiary_id
    ,CASE
    WHEN EXISTS (SELECT 1
    FROM fq_medicineauth
    where source = 'B')
    THEN 'Y'
    ELSE 'N'
    END[Chronic_Indicator]
    FROM dq_beneficiary_snapshot
    --- whats is 'bs' and 'dss' here run simple as provided above in same database where table exists.
    if referring other database then use database_name..table_name

    Cheers,
    Gopal

  4. #4
    Join Date
    Nov 2013
    Location
    Bangalore
    Posts
    30
    Provided Answers: 2
    In Sybase IQ we are using this. You can try this one.

    SELECT
    dss.b_beneficiary_id,
    case when dss.fq_medicineauth = 'B' then 'Y',
    ELSE 'N' END AS [Chronic_Indicator]
    FROM dss.dq_beneficiary_snapshot
    Yuvaraj Subramani

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •