I have a scenario in which I want to show the following columns defined in the query but when I bind the workitems collection to the grid it is getting some columns defined in the query and some are missing, also I am seeing some extra columns which i have not define in the query.
const string wiqlQuery = #"SELECT [System.Id],
[System.Title],
[System.AssignedTo],
[Microsoft.VSTS.Scheduling.CompletedWork],
[Microsoft.VSTS.Scheduling.RemainingWork]
FROM WorkItems
WHERE [System.WorkItemType] = 'Document'
and [Tyler.Document.Type] = '03-Design Document'
ORDER BY [System.Title]";
var workItems = workItemStore1.Query(wiqlQuery);
dataGridView1.DataSource = workItems;
If the fields are custom fields, you are going to have to get them explicitly and bind them explicitly. Only the standard "system" fields are exposed as properties. The rest you have to get through an array.
When your grid has 'autofinding' columns, it could be possible that the returned result shows only the fields that have data.
Related
I try to create a WIQL query that compares field contents of a work item and its related (linked) work items, e.g. where the 'state' of the work item is different from the 'state' of the related work item.
SELECT [System.Id], ... FROM WorkItemLinks WHERE ...
[Source].[System.State] <> [Target].[System.State])
ORDER BY [System.CreatedDate] desc, [System.AssignedTo] mode(MayContain)
(The ... above only indicate the parts that I have ommitted here for clarity.)
When I try to apply the query, I get this error message from TFS:
The link query can not mix expression with different prefixes
Is there a way to compare source and target fields with WIQL?
No, just as the error message indicates, you cannot mix expression with different prefixes. So you cannot compare the field in Source and Target directly. Refer to this link from MSDN for details: http://blogs.msdn.com/b/team_foundation/archive/2010/07/02/wiql-syntax-for-link-query.aspx
However, for the fields with pre-defined list values, you can write the query like following to achieve the feature you want.
SELECT [System.Id] FROM WorkItemLinks WHERE
([Source].[System.State] = ‘New’ and [Target].[System.State] <> ‘New’)
OR ([Source].[System.State] = ‘Resolved’ and [Target].[System.State] <> ‘Resolved’)
OR ([Source].[System.State] = ‘Active’ and [Target].[System.State] <> ‘Active’)
OR ([Source].[System.State] = ‘Closed’ and [Target].[System.State] <> ‘Closed’)
ORDER BY [System.CreatedDate] desc, [System.AssignedTo] mode(MayContain)
I'm using the Laravel's query builder with this syntax :
$article = DB::table('users')->join('articles', 'articles.id', '=', 'users.id')->where('article_id', $id)->first();
You can see that both articles and users table have an id column.
Then in my view I use the query result, and I only get one id whereas I need both.
Is there any way to get them ?
I know I could use :
->select('articles.id as myFirstId', 'users.id as mySecondId', 'users.name', ...)
But there are many columns in this request, and if I can avoid it I'd prefer.
Thanks
Raphaël N.
You can select all fields from the table with higher number of fields with * FROM table and then pick one by one from the other table, like this:
$article = DB::table('users')
->join('articles', 'articles.id', '=', 'users.id')
->where('article_id', $id)
->select('articles.*', 'users.id as userId', 'users.name') // Add rest of `users` fields
->first();
Here is Simple SQL query... I want to get selected field not all table fields by Using Entity frame work List function.
"Select CustName, CustEmail, CustAddress, CustContactNo from Customers"
I assume you already have a context defined and table mapped.
var results = dbContext.Customers.Select(x => new { x.CustName, x.CustEmail, x.CustAddress, x.CustContactNo }).ToList();
I have this query
SELECT
T1.Add,
T1.Edit,
T1.Usr,
T2.FirstName,
T2.LastName
FROM
T2
FULL JOIN
T1 ON T1.Usr = T2.Guid
Is it possible to edit this result from DBGrid ?
I want to add Fields T1.Add and T1.Edit to T1 table
if they are not already there
and change their values.
Thanks
Depending on the used components you could use BeforePost (doing your actions and requery), ModifySQL/insertSQL for IBDataSet, OpdateObject TQuery, etc.
Another way would by using " INSTEAD OF triggers" for a persitant view.
Here is the query (MS SQL):
use DB_432799_satv
select [DB_432799_satv].[dbo].ac_Orders.OrderNumber, OrderDate, PaymentDate,
CompletedDate, ShipDate,DateTimeFinishedPicking,DateTimeShipped,
ShipMethodName, PaymentMethodName
from [DB_432799_satv].[dbo].ac_Orders
Inner join [DB_432799_satv].[dbo].ac_Payments on
[DB_432799_satv].[dbo].ac_Orders.OrderId =
[DB_432799_satv].[dbo].ac_Payments.OrderId
Inner join [DB_432799_satv].[dbo].ac_OrderShipments on
[DB_432799_satv].[dbo].ac_Orders.OrderId =
[DB_432799_satv].[dbo].ac_OrderShipments.OrderId
Inner join [DB_432799_satv].[dbo].[ac_Transactions] on
[DB_432799_satv].[dbo].ac_Payments.paymentid =
[DB_432799_satv].[dbo].ac_Transactions.paymentid
Inner join [SuperATV].[dbo].[tblPartsBoxHeader] on
[DB_432799_satv].[dbo].[ac_transactions].[ProviderTransactionId] =
[SuperATV].[dbo].[tblPartsBoxHeader].[ordernumber]
How would I change this into a stored procedure?
I suspect what you want is what a "view" will give you. Specifically, to store that query in the database and select from it like:
SELECT * FOM myLongQueryView WHERE OrderNumber = 1234;
I don't develop MSSQL, but a quick search turned up this doc page on msdn. I suppose it would go something like this:
CREATE VIEW [DB_432799_satv].myLongQueryView
AS
select [DB_432799_satv].[dbo].ac_Orders.OrderNumber, OrderDate, PaymentDate,
CompletedDate, ShipDate,DateTimeFinishedPicking,DateTimeShipped,
ShipMethodName, PaymentMethodName
from [DB_432799_satv].[dbo].ac_Orders
...
Simply prepend your query with CREATE VIEW [DB_432799_satv].myLongQueryView AS, and use the docs page to decide if any options are desired.
It's important to note that query is stored, not it's current results. So it stays up to date with your data. It is joinable, aggregatable, etc...