Get the Area details from AreaID in TFS 2017 - tfs

It seems there isn't any Database documentation for a given collection in TFS 2017 - e.g. DefaultCollection.
I can get WorkItems from dbo.vw_WorkItemCoreAll & dbo.vw_WorkItemCustomAll, but I can't seem to join on the AreaID that is given to tbl_Area.
What am I missing?

It appears the joining has changed for TFS 2017.
In general I would recommend using the TFS_Warehouse, if the database must be used at all. Areas in TFS_Warehouse are much more straightforward than the TFS_[YOURCOLLECTION] Database.
That being said, if you must use the actual raw database, then here's a query that will join the necessary info:
SELECT * FROM dbo.vw_WorkItemCoreAll w
INNER JOIN dbo.tbl_ClassificationNode c ON w.AreaId = c.Id
WHERE
id = SOMEID
ORDER BY w.Rev DESC
It appears that tbl_Area doesn't contain the actual classifications used for WorkItems anymore.
Disclaimer: This is a last resort - the MSFT preferred mechanism for obtaining this info is the TFS REST API, for the usual API reasons (flexibility, reproducibility, etc.).
In this case I wanted to run an SSRS report (didn't care if it broke in a few months), which works better on raw DBs.

Related

When Edit (delete) Table Columns in Power Query from SQL database , is this edit permanant?

I am trying to connect to my organisation's SQL database using Power Query to create some reports. I need to delete/edit some tables and join multiple tables to come up with the desired report output...
I don't want the change or edit I will do on the excel-power query to reflect on the live database but just in excel .
The short answer is no, any button you press in the Power Query Editor interface does not modify the source database. I must admit that I have not found any page in the Microsoft Docs on Power Query that states this clearly. The page What is Power Query? states that:
Power Query is a data transformation and data preparation engine. Power Query comes with a graphical interface for getting data from sources and a Power Query Editor for applying transformations.
Other pages contain similarly general and vague descriptions but let me reassure you that any data transformation you carry out by using the Power Query Editor interface will not modify your SQL database. All you see in Power Query is a view of the source database.
Seeing as you are connecting to a SQL database, it is likely that query folding is activated. This means that when you remove a column (or row), this will update the SQL query used to extract the data from the database. That query is written as a single SELECT statement that can contain multiple clauses like GROUP BY and WHERE. Transformations that add data (e.g. Add Custom Column, Fill Down) are not included in the query, they are carried out only within the Power Query engine. You can read more about this in the docs.
How to edit a database with Power Query when native SQL queries are supported
That being said, you can actually edit a database from within Power Query if the database supports the use of native SQL queries, if you have write permission for the database, and if you edit and run one of the two M functions that let you write native SQL queries. Here is an example using the Sql.Database function:
Sql.Database("servername", "dbname", [Query = "DROP TABLE tablename"])
And here is an example using the Value.NativeQuery function:
Source = Sql.Databases("servername"){[Name="dbname"]}[Data],
#"Native Query" = Value.NativeQuery(Source, "DROP TABLE tablename")
Unless you have changed the default Query Options, these functions should raise a warning message requiring you to permit running the query:
This prevents you from modifying the database without confirmation, so any database modification cannot happen just by accident.
I verified this using Excel Microsoft 365 (Version 2108) on Windows 10 64-bit connected to a local SQL Server 2019 (15.x) database.

How to query for work items for current team in TFS?

I am getting started with TFS 2015 and I need to know how to make a query that returns all of the work items for the current iteration for the current team. I have Iteration Path Under #CurrentIteration and Work Item Type = User Story, but I can find a macro similar to #CurrentIteration that would get the current team or team area. How do I filter out the stories for all other teams?
It's not able to do this through a query. You could check the Query macros or variables, use the macros described in the following table to filter your queries based on specific fields. There is not any team area related macro.
Besides, actually as far as I know work items can only be assigned to specific people not groups. However, for a workaround. By assigning a work item to a specific area path you basically assign it to a team. If you use the area path for something else today, you can also use another string field in the work item that specifies the team.
(https://www.visualstudio.com/docs/work/scale/portfolio-management)
So you could use Area Path to do the filter.
This won't directly solve your problem but you can use 'Assigned to' 'In Group' and then use a user group e.g. '[Home]\Team NI'. This will return tickets assigned to the group or group members but assumes the tickets are assigned appropriately (rather than being unassigned). YMMV but I've found it useful at times to get around this limitation. TFS Azure 2019 now also includes #TeamAreas - which is helpful unless you have multiple teams using the same areas.

Merging 4 queries in Cognos Report Studio

Recently started working on Cognos and I am facing quite a few challenges. Though some of them I was able to rectify, with some of them I'm just not able to understand the problem. I am creating a report in Cognos where I used a SQL code to join 4 tables.
Two of the data items in that query are Primary_Officer_ID and Relationship_Officer_ID
Have another table, with field name Emp_ID and Emp_Names. Note that the Emp_ID is same as the officer’s numbers in the Primary_Officer_ID and Relationship_Officer_ID.
I want a report which gives the Names of the officers in place of their IDs.
Below are the 4 queries used
Query1: SQL code
Query2: Emp_ID, Emp_Names
Query3: Left outer join for Primary_Officer_ID
Query4: Left outer join for Relationship_Officer_ID
The final dataset used is Query 4. As it includes all the joins and SQL code
When I run the report, it only gives me names for Primary_Officer_ID and not for Relationship_Officer_ID. Please suggest what shall I do differently to make the report run successfully.
Attached is the snapshot of Query Explorer which will help to understand the scenario:
I suppose you should create another query EmpNames1 (copy of EmpNames) and use it in second join.
You can check out generated SQL for "Relationship Officer Join" to see the what's wrong.

TFS 2010: Real time reporting

I would like to create a report that shows the iteration status in real time. I was able to create a query on the Tfs_Warehouse database (see below) however I found that this database is populated from the Tfs_Collection database on timely basis.
Is there a way that I can see the changes to the work items reflected in the report right away?
SELECT *
FROM [CurrentWorkItemView] c
left join [vDimWorkItemTreeOverlay] t on t.WorkItemSK = c.WorkItemSK
where c.IterationName = #iteration and c.System_WorkItemType = 'User Story'
order by c.Microsoft_VSTS_Common_StackRank, c.System_id
Note: this not the full query because I couldn't fit it nicely. Basically it joins 2 table (CurrentWorkItemView and vDimWorkItemTreeOverlay) to get the user stories and associated tasks to each user story.
No, not through the warehouse. When you need up to date information from the work items, use a work item query in Excel or Visual Studio.
You can also use the TFS api to query the operational datastore directly.

Performance of generated T-SQL from Entity Framework

I recently used Entity Framework for a project, despite my DBA's strong disapproval. So one day he came to my office complaining about generated T-SQL that reaches his database.
For instance, when I want to select a product based on the id, I write something like this:
context.Products.FirstOrDefault(p=>p.Id==id);
Which translates to
SELECT ... FROM (SELECT TOP 1 ... FROM PRODUCTS WHERE ID=#id)
So he is shouting, "Why on earth would you write a SELECT * FROM (SELECT TOP 1)"
So I changed my code to
context.Products.Where(p=>p.Id==id).ToList().FirstOrDefault()
and this produces a much cleaner T-SQL:
SELECT ... FROM PRODUCTS WHERE ID=#id
The inner query and the TOP 1 dissappeared. Enough mambling, my question is this: Does the first query really put an overhead for SQL Server? Is it harder to parse than the second method? The Id column has a Clustered index on. I want a good answer so I can rub it on his face (or mine)
Thanks,
Themos
Have you tried running the queries manually and comparing the executions plans?
The biggest problem here isn't that the SQL isn't perfectly formed to your DBA's standards (although I'm fairly certain that the query engine will optimize out the extra select). The second query actually returns the entire contents of the Products table which you then analyse in memory and this is definitely a task that should be performed by the DB and not the application layer.
In short, he's being a pedant; leave it the way it was.

Resources