• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Returning an additional column in sql

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

0
wolivier69
Asked:
wolivier69
  • 2
1 Solution
 
KrtyknmCommented:
I believe you need an column that shows the staffName when the Parent = @root and i hope the below query will help you.

SELECT
      DISTINCT
      StaffName ,
      StaffNumber,
      Level,
      SeniorName,
      Parent,
      CASE
            WHEN Parent = @Root THEN StaffName
            ELSE NULL
      END [ParentStaffName]
FROM Children
Order By StaffName

Please let me know if i misunderstood your question.

Thanks,
Karthik
0
 
wolivier69Author Commented:
thanks a lot works perfectly!
0
 
wolivier69Author Commented:
Work perfectly as i wanted it to
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now