Posted on 2011-04-26
Last Modified: 2012-05-11
I think I need a subquery here, but I do not know for sure and I have no experience with them. I have a SQL Server 2005 database. I need to create a view that will return all of the records with a certain status that I'm responsible for. My responsibility is determined by the code the record is assigned that conincides with the codes I'm responsible for. There are 100 different codes, and I can me assigned to any number fo them. So the main record table has 1500 records in it. Each record has a status(1, 2, 3, 4) and a code(a, b, c, d, etc.). I am assigned to 5 different codes (a, b, c, d, e). I want to return any record with a status of 1 in any of the codes I'm assigned to. What is the best way to do this? I hope this is clear. Thanks
Question by:dodgerfan
    LVL 15

    Accepted Solution

    Here's an example that should work...

    SELECT main_table.* FROM main_table, my_codes WHERE main_table.code = my_codes.code AND my_codes.person = me AND main_table.status = 1

    Open in new window

    LVL 40

    Assisted Solution

    Post the table structure, sample data and the expected result.

    I am assuming you have one table and want the data from that table for your codes and stats = 1.
    select * from tblMain where code in ('a','b','c','d','e') and status = 1 

    Open in new window

    LVL 21

    Assisted Solution

    by:Alpesh Patel
    Select * from Table where Status = 1 and code in (a, b, c, e, f)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
    Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now