• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1719
  • Last Modified:

Using Ternary operators in Sybase

Hey,
      I have a problem writing a select statement

       SELECT
       isnull(ltrim(rtrim(A.MBS_POOL_SBTP_CD)),'Fixed'),                                      
       @FNMA,                                    
       'MF',                                    
       'MBS'
      FROM disclosure..MBS_POOL_AT_ISSN A, #CUSIPS B, disclosure..SECU C
      WHERE A.SECU_CUSIP_ID = B.CUSIP
      and B.CUSIP    = C.SECU_CUSIP_ID

      In the above Query , the function,  isnull(ltrim(rtrim(A.MBS_POOL_SBTP_CD)),'Fixed') writtens a value 'Fixed' if the column A.MBS_POOL_SBTP_CD is null. But what i want  is as follows

isnull(ltrim(rtrim(A.MBS_POOL_SBTP_CD)),'Fixed'|'ARM')--- Meaning when the value of A.MBS_POOL_SBTP_CD is null it should return FIXED and when there is an existing value for  A.MBS_POOL_SBTP_CD   it should return ARM to that specified column during the select. Actually it should mimic the following if/else condition


if (A.MBS_POOL_SBTP_CD  = null){
return 'Fixed'
}else {
return 'ARM'
}

I am not Sure how to code this in Sybase select statements.

Thanks.
0
SubhaBabu
Asked:
SubhaBabu
1 Solution
 
Jan FranekCommented:
Use CASE command:

select case when A.MBS_POOL_SBTP_CD is null then 'Fixed' else 'ARM' end
....

For detailed info see http://manuals.sybase.com/onlinebooks/group-as/asg1251e/commands/@Generic__BookTextView/5954;pt=5954#X
0
 
morisceCommented:
SELECT
       case A.MBS_POOL_SBTP_CD when null then 'Fixed' else 'ARM' end,
       @FNMA,                                    
       'MF',                                    
       'MBS'
      FROM disclosure..MBS_POOL_AT_ISSN A, #CUSIPS B, disclosure..SECU C
      WHERE A.SECU_CUSIP_ID = B.CUSIP
      and B.CUSIP    = C.SECU_CUSIP_ID

If you want processing empty string like null value :
SELECT
       case isnull(A.MBS_POOL_SBTP_CD,'') when '' then 'Fixed' else 'ARM' end,
       @FNMA,                                    
       'MF',                                    
       'MBS'
      FROM disclosure..MBS_POOL_AT_ISSN A, #CUSIPS B, disclosure..SECU C
      WHERE A.SECU_CUSIP_ID = B.CUSIP
      and B.CUSIP    = C.SECU_CUSIP_ID
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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