Subrequest in WIQL - tfs

How can I use subrequest in WIQL TFS?
I need something like this
SELECT
[System.Id]
FROM workitems
WHERE [System.Id] IN (
SELECT
[System.Id]
FROM workitems
WHERE [System.Title] == 'Example'
)

Sorry, this is not available at present. There has already been a related user voice here:
TFS: Queries based on results of other queries
https://visualstudio.uservoice.com/forums/330519-azure-devops-formerly-visual-studio-team-services/suggestions/2300378-tfs-queries-based-on-results-of-other-queries
As a workaround to execute sub queries or joins using the TFS query execution engine you will have to use the method RunLinkQuery().
For a detail sample you could take a look at this blog: Using the TFS API to display results of a Hierarchical Work Item Query

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.

Get the Area details from AreaID in TFS 2017

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.

Dynamics CRM OData query filtering on expanded attributes only works if no results come out?

I have a requirement to fetch Price List Item records which adhere to the following requirements:
Filter by a specific PriceList
Filter by a specific currency
Filter by the Name of the related Product containing a given string
I got the first two points working no problem, but it feels like expanding doesn't cope well with filtering. I started from a "straight" query on Product entity:
.../ProductSet?$filter=substringof('sometext', Name)
Equivalent SQL (targeting the corresponding CRM filtered views for clarity):
SELECT * FROM FilteredProduct WHERE ProductNumber LIKE '%sometext%'
The above query works, I can tweak it and have no issues. However, if I attempt to move on to ProductPriceLevel (thus expanding the relationship with Product, which is product_price_levels) I end up with this:
.../ProductPriceLevelSet?$expand=product_price_levels&$filter=substringof('sometext', product_price_levels/Name)
Equivalent SQL (again, targeting the relevant filtered views):
SELECT * FROM FilteredProductPriceLevel PPL JOIN FilteredProduct P
ON PPL.ProductId = P.ProductId WHERE P.ProductNumber LIKE '%sometext%'
Which has two different outcomes I see:
If the $filter has no matches, it works fine and returns an empty result set
If the $filter matches something, I get an error
code: -2147220970
message: The result selector of the 'Join' operation must return an anonymous type of two properties.
AFAIK that's what happens when you hit a limitation of LINQ-to-CRM regarding using .Where() on multiple entities at once... doesn't seem relevant!
What's wrong with my query ?
NOTE: The CRM 2013 I'm using is On-Premise, without any update rollup / service pack.
ALSO NOTE: The equivalent SQL, as can be expected, works perfectly
I don't think CRM OData supports adding a filter on a joined entity. Try reversing the entity you're actually starting with, and add a path to the referencing entity:
ProductSet()?$filter=substringof('sometext',ProductNumber)&$expand=product_price_levels&$select=product_price_levels/*
P.S. If you have linqPad, this is the query I used to generate this:
from p in ProductSet
where p.ProductNumber.Contains("sometext")
select new { p.product_price_levels }

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.

Notion of a branch in TFS_Warehouse

I'm trying to enhance the following query such that it returns all change sets on a specific branch. Unfortunately, I can't seem to find the notion of a branch in the warehouse.
SELECT [ChangesetSK]
,[ChangesetTitle]
,[LastUpdatedDateTime]
,[CheckedInBy__Name]
FROM [Tfs_Warehouse].[dbo].[vDimChangesetOverlay]
Where [LastUpdatedDateTime] > '2012-11-26 00:00:00'

Resources