Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    1

    Unanswered: Nested or Subquery help

    i am new to SQL Server DB.
    i have a typical query problem.
    master table contains Data in following format
    id stype sid svalue
    1 status 1 approved
    2 status 2 pending
    3 request 1 draft
    4 request 2 waiting
    etc

    in my query i need to substitute the svalue in place of sid
    e.g.
    select requestid ,bstatus, brequest from request ;
    should give
    ---------------------------------
    R1122 approved draft
    ------------------------------
    instead of
    R1122 1 1
    *****************
    link field is column name (quite unusual )
    like for status column , it is bstatus column name and it is stored in master table as status .


    i need to do the following in 1 query only.
    kindly suggest some nested query to do the same
    kindly help
    Smita

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select requestid 
         , s.svalue  as statusvalue
         , r.svalue  as requestvalue
      from request
    inner
      join master as s
        on bstatus = s.sid
       and s.stype = 'status'
    inner
      join master as r
        on bstatus = r.sid
       and r.stype = 'request'
    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
  •