Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    1

    Unanswered: if else cond for select statement

    Hi
    I need if else cond for my sql,
    I have ACCOUNT is my master table contains account id is the column for comparing for other tables.

    I have other two child tables contains account id column in both the tables.

    my data will be there in my master table all account id information.
    similarly my data will be the in my child tables either one of them either first child table or second child table.

    how can i write my sql select query for getting the data by comparing account id

    tryign to this way..plz correct me

    CASE WHEN(INNER JOIN CRMDETAILS ON CRMDETAILS.ACID = ADVACDETAIL.ACID)
    THEN
    CRMDETAILS.CRMSECUID AS CRMSECUID,
    CRMDETAILS.DTOFISSUE AS DTOFISSUE,
    CRMDETAILS.DTOFMATURITY AS DTOFMATURITY,
    CRMDETAILS.CURRENTVALUE AS CURRENTVALUE,
    ELSE
    PRIMARY_SECURITY.CRMSECUID AS CRMSECUID,
    PRIMARY_SECURITY.CURRENTVALUE AS CURRENTVALUE,
    PRIMARY_SECURITY.DTOFISSUE AS DTOFISSUE,
    PRIMARY_SECURITY.DTOFMARTURITY AS CURRENTVALUE


    Thanks
    Venkatesh

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    try looking at union

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try two LEFT OUTER JOINs
    Code:
    SELECT COALESCE(crmdetails.crmsecuid   
                   ,primary_security.crmsecuid    ) AS crmsecuid        
         , COALESCE(crmdetails.dtofissue        
                   ,primary_security.dtofissue    ) AS dtofissue   
         , COALESCE(crmdetails.dtofmaturity     
                   ,primary_security.dtofmaturity ) AS dtofmaturity
         , COALESCE(crmdetails.currentvalue     
                   ,primary_security.currentvalue ) AS currentvalue
      FROM advacdetail
    LEFT OUTER
      JOIN crmdetails 
        ON crmdetails.acid = advacdetail.acid
    LEFT OUTER
      JOIN primary_security
        ON primary_security.acid = advacdetail.acid
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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