• IIRC =* is a right join, not a left join. *= is a left join.

    SELECT A.recid,

    A.id,

    A.PROCID,

    A.pstatus,

    B.pname,

    B.pdesc,

    LEN(pname) AS plen,

    CASE WHEN C.seq IS NULL THEN 0 ELSE 1 END AS DISABLED

    FROM lprocs A,

    inner join master B on A.PROCID = B.PROCID

    right join pmap C on C.PROCID = A.PROCID

    and C.typeid = (SELECT D.typeid FROM loan D WHERE D.id = A.id) --be careful here, this subquery could return more than 1 row

    WHERE A.id = @id

    ORDER BY pname

    Be careful with that subquery, the subquery may return more than 1 row.

    As a side note, it is a pet peeve of mine to use aliases a,b,c,d. They don't mean anything and I find actually make it more difficult to work with. You have to constantly keep referring to the from section of your query to remember which table is which.

    Something like this. It is much easier to know what table any given column belongs to.

    SELECT p.recid,

    p.id,

    p.PROCID,

    p.pstatus,

    m.pname,

    m.pdesc,

    LEN(pname) AS plen,

    CASE WHEN m.seq IS NULL THEN 0 ELSE 1 END AS DISABLED

    FROM lprocs p,

    inner join [master] m on p.PROCID = m.PROCID]

    inner join loan l on l.id = p.id

    right join pmap m on m.PROCID = p.PROCID

    and m.typeid = l.typeid

    WHERE p.id = @id

    ORDER BY pname

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/