Returning an additional column in sql

Posted on 2011-05-10
Last Modified: 2012-05-11
I have a query that returns all the data that i want but i also want to add an additional column. The query is below. I want to select everything from the table and add an additional column where it gets all the staffNames where Parent = @Root  and if it not equal to that then a null value gets put in its place.

Thanks for any help that could be provided
SELECT Distinct StaffName ,StaffNumber,Level,SeniorName,Parent
FROM Children
Order By StaffName

Open in new window

Question by:wolivier69
    LVL 3

    Accepted Solution

    I believe you need an column that shows the staffName when the Parent = @root and i hope the below query will help you.

          StaffName ,
                WHEN Parent = @Root THEN StaffName
                ELSE NULL
          END [ParentStaffName]
    FROM Children
    Order By StaffName

    Please let me know if i misunderstood your question.


    Author Comment

    thanks a lot works perfectly!

    Author Closing Comment

    Work perfectly as i wanted it to

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    730 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

    18 Experts available now in Live!

    Get 1:1 Help Now