I have a View that is pretty complex. The query pulls data from about 14 tables with a subquery involved also. The results are as follows:
[Unique Identifier][office][number][description][value][customer][strjobid]…
Now this information is pulled from a View called ViewTeamMembers. The ViewTeamMembers view will return all team members per a unique identifier. There are times when there are team members but there is no “Owner”. I need my query to pull the data from ViewTeamMembers (Which is is doing now) and check if there is an owner. If there is not an owner, I need to insert a row into my result set where the owner name would be “Not Assigned” and all of the other data would be populated by the data from the other team members. How can I get this accomplished?
Example:
ViewTeamMembers
[unique123][Office1][555-5555][description][1,000][Frank][hourly]
[unique123][Office1][555-5555][description][1,000][Tom][Salary]
[unique123][Office1][555-5555][description][1,000][Brent][Hourly]
I need to query against that and see if there is a row that exists that has someone with the jobid “Owner” and if not, I need to insert my own row into my view with
[unique123][Office1][555-5555][description][1,000][Not Assigned][Owner]
so when I view my query result set I should get
[unique123][Office1][555-5555][description][1,000][Frank][hourly]
[unique123][Office1][555-5555][description][1,000][Tom][Salary]
[unique123][Office1][555-5555][description][1,000][Brent][Hourly]
[unique123][Office1][555-5555][description][1,000][Not Assigned][Owner]
This is my join
LEFT OUTER JOIN
dbo.viewteammembers ON dbo.viewteammembers.guidrequirementid = dbo.tblrequirements.guidrequirementid
I would assume I would have to do something like this:
select * from viewteammembers case when not exists(select * from viewteammebers where strjobid = 'Owner') then
but I don’t know what the syntax is to make this work.
Thanks!
Depending on the type of database you use there might be nicer ways to do this but something like this should do the trick