TFS2015 - How can I recover shelved changes - tfs

Same situation as this [question]: TFS Meltdown - How can I recover shelved changes but for TFS2015. The issue I'm having is I can't find the files that were added or renamed in my query result.
SELECT c.[CreationDate], c.[Content], vi.ChildItem, vi.ParentPath
FROM [dbo].[tbl_Content] c
INNER JOIN [dbo].[tbl_FileMetadata] fm ON fm.ResourceId = c.ResourceId
INNER JOIN [dbo].[tbl_FileReference] fr ON fr.ResourceId = fm.ResourceId
INNER JOIN [dbo].[tbl_PendingChange] pc ON pc.FileId = fr.FileId
INNER JOIN [dbo].[tbl_Workspace] w ON w.WorkspaceId = pc.WorkspaceId
INNER JOIN [dbo].[tbl_Version] vi ON vi.ItemId = pc.ItemId AND vi.VersionTo = 2147483647
WHERE w.WorkspaceName = 'SHELVESET_NAME'
UPDATE:
Was able to figure out the query.
SELECT w.WorkspaceId, c.[CreationDate], c.[Content], pc.TargetChildItem, pc.TargetParentPath
FROM [dbo].[tbl_Content] c
JOIN [dbo].[tbl_FileMetadata] fm ON fm.ResourceId = c.ResourceId
JOIN [dbo].[tbl_FileReference] fr ON fr.ResourceId = fm.ResourceId
JOIN [dbo].[tbl_PendingChange] pc ON pc.FileId = fr.FileId
JOIN [dbo].[tbl_Workspace] w ON w.WorkspaceId = pc.WorkspaceId
WHERE w.WorkspaceName = 'SHELVESET_NAME'

I was able to figure out the query by looking at table tbl_PendingChange and looking for the new files that was added and then correctly updated the original query.

Related

how can i use inner join in solr

SELECT A.ioTDeviceKind, B.resourceRiskLevelLowCount, B.resourceRiskLevelMiddleCount, B.resourceRiskLevelHighCount FROM ioTDevice AS A JOIN resourcelogCurrent AS B ON A.ioTDeviceKind = B.ioTDeviceKind WHERE A.resourceId = 'airconditinal'
or
SELECT A.ioTDeviceKind, B.resourceRiskLevelLowCount, B.resourceRiskLevelMiddleCount, B.resourceRiskLevelHighCount FROM ioTDevice AS A INNER JOIN resourcelogCurrent AS B ON A.ioTDeviceKind = B.ioTDeviceKind WHERE A.resourceId = 'airconditinal'
but the result is null.
there is no error, but the result always is null,
where i user left join, there is no error..
please help me , how can i use inner join in solr??

PSQL query to comapre data from two instances of a database

I have two instances of the same database from different days. All tables from one day are called tableA* and from the other tableB*. I would like to compare data to see what have changed. I would like to select all rows that don't match exactly. So for example if one value is different in tables tableA1 and tableB1 I would like to select a corresponding row from table A and mark it as 'new' and from table B and mark it as 'deleted'. I tried with a query like this:
SELECT 'new', ta1.name, ta2.name, ta3.name, ta4.name, ta5.name
FROM tableA1 ta1
LEFT JOIN tableA2 ta2 ON ta1.ta2_id = ta2.id
LEFT JOIN tableA3 ta3 ON ta1.ta3_id = ta3.id
LEFT JOIN tableA4 ta4 ON ta1.ta4_id = ta4.id
LEFT JOIN tableA5 ta5 ON ta5.ta1_id = ta1.id WHERE NOT EXISTS
(SELECT tb1.name, tb2.name, tb3.name, tb4.name, tb5.name
FROM tableB1 tb1
LEFT JOIN tableB2 tb2 ON tb1.tb2_id = tb2.id
LEFT JOIN tableB3 tb3 ON tb1.tb3_id = tb3.id
LEFT JOIN tableB4 tb4 ON tb1.tb4_id = tb4.id
LEFT JOIN tableB5 tb5 ON tb5.tb1_id = tb1.id WHERE
tb1.name = ta1.name AND
tb2.name = ta2.name AND
tb3.name = ta3.name AND
tb4.name = ta4.name AND
tb5.name = ta5.name)
UNION
SELECT 'deleted', tb1.name, tb2.name, tb3.name, tb4.name, tb5.name
FROM tableB1 tb1
LEFT JOIN tableB2 tb2 ON tb1.tb2_id = tb2.id
LEFT JOIN tableB3 tb3 ON tb1.tb3_id = tb3.id
LEFT JOIN tableB4 tb4 ON tb1.tb4_id = tb4.id
LEFT JOIN tableB5 tb5 ON tb5.tb1_id = tb1.id WHERE NOT EXISTS
(SELECT ta1.name, ta2.name, ta3.name, ta4.name, ta5.name
FROM tableA1 ta1
LEFT JOIN tableA2 ta2 ON ta1.ta2_id = ta2.id
LEFT JOIN tableA3 ta3 ON ta1.ta3_id = ta3.id
LEFT JOIN tableA4 ta4 ON ta1.ta4_id = ta4.id
LEFT JOIN tableA5 ta5 ON ta5.ta1_id = ta1.id WHERE
tb1.name = ta1.name AND
tb2.name = ta2.name AND
tb3.name = ta3.name AND
tb4.name = ta4.name AND
tb5.name = ta5.name)
Hoping that if I created the same stuructre and compare all the values I would get the anticipated result. Even if databases are the same I get a lot row selected.
Found the problem. When comparing two NULL values the result is FALSE, the query itself should be fine. So I should have added conditions to check whether values are NULL.

join querybuilder ax 2012 x++

Excuse my english (is not my native language)
Well, i wanna make this query (i make the temp table EMPL, the first temp table VEN is very easy but i don't see how to make the join)
SELECT 'CADORE_MP',EMPL.PERSONNELNUMBER, EMPL.NOMBRE, 0 AS CANTIDAD, VEN.MONTO FROM
(
SELECT VATNUM, SUM(INVOICEAMOUNT) AS MONTO FROM CUSTINVOICEJOUR
WHERE INVOICEDATE>=#FECHAI and INVOICEDATE<=#FECHAF
AND PAYMENT LIKE '%DIAS%'
AND CUSTGROUP LIKE 'EMP%'
AND REVERSE_GT=0 AND TAXTYPEDOCUMENTID='FC'
GROUP BY VATNUM) VEN
INNER JOIN
(
SELECT HW.PERSONNELNUMBER, HPIN.IDENTIFICATIONNUMBER, PRE.FIRSTNAME+' '+PRE.SECONDNAME+' '+PRE.FIRSTLASTNAME+' '+PRE.SECONDLASTNAME AS NOMBRE
FROM HcmPersonIdentificationNumber HPIN INNER JOIN HCMWORKER HW ON HPIN.PERSON=HW.PERSON AND HPIN.IDENTIFICATIONTYPE=5637146829
INNER JOIN PAYROLLEMPL PRE ON HW.PERSON=PRE.PERSON
INNER JOIN HCMEMPLOYMENT HE ON HW.RECID=HE.WORKER
LEFT JOIN PAYROLLLIQUIDATION PL ON HW.PERSONNELNUMBER=PL.EMPLID AND PL.DATELOW<#FECHAF
LEFT JOIN PAYROLLGROUPEMPLOYEES PRGE ON HW.PERSONNELNUMBER=PRGE.EMPLID AND GROUPSEMPLYEESID='CADORE_PQ'
WHERE HE.VALIDTO>='21541231' AND PL.EMPLID IS NULL AND PRGE.EMPLID IS NULL) EMPL ON VEN.VATNUM=EMPL.IDENTIFICATIONNUMBER
it have some parameters and other are constants.
so, i can do the two inner selects but later i can't do the join of this two temp tables
and i wanna know if someone can explain me the diference of join, exists join, no exists join. something like this
and if is posible to make when only wanna data from A but do not intersect with B
This is what i have
Query query;
QueryRun Run;
QueryBuildDataSource dataSourceHW;
QueryBuildDataSource dataSourceHPIN;
QueryBuildDataSource dataSourcePRE;
QueryBuildDataSource dataSourceHE;
QueryBuildDataSource dataSourcePL;
QueryBuildDataSource dataSourcePRGE;
str textDesc = "";
date FechaF;
FechaF = str2Date('21/03/2016',123);
query = new Query();
dataSourceHW = query.addDataSource(tableNum(HcmWorker));
dataSourceHPIN = dataSourceHW.addDataSource(tableNum(HcmPersonIdentificationNumber));
dataSourceHPIN.addLink(fieldNum(HcmWorker, Person), fieldNum(HcmPersonIdentificationNumber, Person));
dataSourceHPIN.addRange(fieldnum(HcmPersonIdentificationNumber,IdentificationType)).value('5637146829');
dataSourceHPIN.fetchMode(QueryFetchMode::One2One);
dataSourceHPIN.joinMode(JoinMode::InnerJoin);
dataSourcePRE = dataSourceHW.addDataSource(tableNum(PayRollEmpl), "PayRollEmpl");
dataSourcePRE.addLink(fieldNum(HcmWorker, Person), fieldNum(PayRollEmpl, Person));
dataSourcePRE.fetchMode(QueryFetchMode::One2One);
dataSourcePRE.joinMode(JoinMode::InnerJoin);
dataSourceHE = dataSourceHW.addDataSource(tableNum(HcmEmployment), "HcmEmployment");
dataSourceHE.addLink(fieldNum(HcmWorker, RecId), fieldNum(HcmEmployment, Worker));
dataSourceHE.addRange(fieldnum(HcmEmployment,ValidTo)).value(strFmt('%1' ,DateTimeUtil::maxValue()));
dataSourceHE.fetchMode(QueryFetchMode::One2One);
dataSourceHE.joinMode(JoinMode::InnerJoin);
dataSourcePL = dataSourceHW.addDataSource(tableNum(PayRollLiquidation));
dataSourcePL.addLink(fieldNum(HcmWorker, PersonnelNumber), fieldNum(PayRollLiquidation, EmplId));
dataSourcePL.addRange(fieldnum(PayRollLiquidation,DateLow)).value('21/03/2016');
dataSourcePL.fetchMode(QueryFetchMode::One2One);
dataSourcePL.joinMode(JoinMode::OuterJoin);
// this join under this dont work, indistinctly if i use it, always show me the same
// because of this i ask above about the data of table A only
dataSourcePRGE = dataSourceHW.addDataSource(tableNum(PayRollGroupEmployees));
dataSourcePRGE.addLink(fieldNum(HcmWorker, PersonnelNumber), fieldNum(PayRollGroupEmployees, EmplId));
dataSourcePRGE.addRange(fieldnum(PayRollGroupEmployees,GroupsEmplyeesId)).value('CADORE_PQ');
//dataSourcePRGE.addRange(fieldnum(PayRollGroupEmployees,EmplId)).value(SysQuery::valueEmptyString());
dataSourcePRGE.fetchMode(QueryFetchMode::One2One);
dataSourcePRGE.joinMode(JoinMode::NoExistsJoin);
will thanks you if someone help me

How to simulate Subqueries in the ON Clause in Vertica database?

Hy everbody , i am having some trouble in transforming a query that has a set of subqueries in the ON clause.
The initial code was created in SQL Server and i have changed to work on Vertica.
This is the code :
SELECT
DISTINCT DocFinanceiro.AutoId AS AutoId,
DocFinanceiro.Classe AS ClasseDoc,
EspecPrestador.Seq AS Sequencia,
PrestadorServico.Codigo AS CodigoPrest,
PessoaPrest.Nome AS NomePrestador,
DocFinanceiro.CompFinanceira AS CompFinanceira,
EspecialidadeServico.Nome AS Especialidade,
ClassePrestador.Nome AS ClsPrestador,
RegistroPessoa.Numero AS RegistroINSS,
RegistroPessoa.Tipo AS TipoRegPessoa,
DocFinanceiro.DataVencimento AS DataVencimentoDocFin
FROM DocFinanceiro
INNER JOIN ClasseDocFinanceiro
ON DocFinanceiro.Classe = ClasseDocFinanceiro.Codigo
INNER JOIN ItemFinanceiro ON DocFinanceiro.AutoId = ItemFinanceiro.Documento
INNER JOIN ClasseApropriacaoFinan
ON ItemFinanceiro.ClasseApro = ClasseApropriacaoFinan.Codigo
INNER JOIN ContratoFinanceiro
ON DocFinanceiro.ContratoFinanceiro = ContratoFinanceiro.AutoId
INNER JOIN Pessoa ON ContratoFinanceiro.Pessoa = Pessoa.AutoId
INNER JOIN GeradorItemFinan
ON ItemFinanceiro.AutoId = GeradorItemFinan.ItemFinan
INNER JOIN PrestadorServico
ON ContratoFinanceiro.AutoId = PrestadorServico.ContratoFinanceiro
INNER JOIN Pessoa PessoaPrest ON PrestadorServico.Pessoa = PessoaPrest.AutoId
INNER JOIN TipoValorFinan
ON ClasseApropriacaoFinan.TipoValor = TipoValorFinan.Codigo
INNER JOIN ClasseContratoFinanceiro
ON ContratoFinanceiro.Classe = ClasseContratoFinanceiro.AutoId
INNER JOIN ClassePrestador
ON PrestadorServico.Classe = ClassePrestador.Codigo
LEFT JOIN EspecPrestador
ON EspecPrestador.Prestador = PrestadorServico.AutoId
AND EspecPrestador.Seq = 1
LEFT JOIN EspecialidadeServico
ON EspecialidadeServico.AutoId = EspecPrestador.Especialidade
LEFT JOIN RegistroPessoa ON PessoaPrest.AutoId = RegistroPessoa.Pessoa
--This is the part where i getr stuck
AND
(
RegistroPessoa.AutoId =
(
SELECT
RegistroPessoa.AutoId
FROM RegistroPessoa
WHERE RegistroPessoa.Pessoa = PessoaPrest.Autoid
AND (RegistroPessoa.Tipo = 1 OR RegistroPessoa.Tipo = 1) order by 1 limit 1
)
)
--until here
WHERE (GeradorItemFinan.TipoGerador = 1)
AND (DocFinanceiro.CompFinanceira = 1)
AND (PrestadorServico.AutoId = 1)
AND DocFinanceiro.CompSeq = 1
AND (DocFinanceiro.Numero IS NOT NULL)
AND (DocFinanceiro.Classe <> 1)
ORDER BY AutoId, Sequencia
;
If anybody has any ideas it would be great !!
try replace
RegistroPessoa.AutoId = (SELECT...)
to
RegistroPessoa.AutoId IN (SELECT...)
and use aliases for table short names

Sql Server queries optimization techniques

My Stored Procedure takes a very long time to execute.
Can anyone suggest me what I can do to speed up the stored procedure, apart from using some good practices for writing down the queries.
I've heard about creating indices, but I'm not sure what are they.
Please suggest all the best ways to speed up my queries.
Thanks
CREATE PROCEDURE [dbo].[usp_GetAlternates]
(
#NNumber CHAR(11) ,
#pid INT ,
#pbmid INT
)
AS
BEGIN
TRUNCATE TABLE TempTherapeuticAlt
INSERT INTO TempTherapeuticAlt
SELECT NULL AS MedicationID ,
PR.ePrescribingName AS MedicationName ,
U.Strength AS MedicationStrength ,
FRM.FormName AS MedicationForm ,
PR.DEAClassificationID AS DEASchedule ,
NULL AS NDCNumber
FROM Product PR
JOIN ( SELECT MP.MarketedProductID
FROM table2 TCTSP
JOIN table3 MP ON MP.SpecificProductID = TCTSP.SpecificProductID
JOIN ( SELECT TCTSP.TherapeuticConceptTreeID
FROM table3 MP
JOIN table2 TCTSP ON MP.SpecificProductID = TCTSP.SpecificProductID
JOIN ( SELECT
PR.MarketedProductID
FROM
table4 PA
JOIN Product PR ON PA.ProductID = PR.ProductID
WHERE
PA.NDC11 = #NNumber
) PAPA ON MP.MarketedProductID = PAPA.MarketedProductID
) xxx ON TCTSP.TherapeuticConceptTreeID = xxx.TherapeuticConceptTreeID
) MPI ON PR.MarketedProductID = MPI.MarketedProductID
JOIN ( SELECT P.ProductID ,
O.Strength ,
O.Unit
FROM Product AS P
INNER JOIN table3 AS M ON P.MarketedProductID = M.MarketedProductID
INNER JOIN table5 AS S ON M.SpecificProductID = S.SpecificProductID
LEFT OUTER JOIN table6 AS O ON S.SpecificProductID = O.SpecificProductID
GROUP BY P.ProductID ,
O.Strength ,
O.Unit
) U ON PR.ProductID = U.ProductID
JOIN ( SELECT PA.ProductID ,
S.ScriptFormID ,
F.Code AS NCPDPScriptFormCode ,
S.FormName
FROM table4 AS PA
INNER JOIN table7 AS S ON PA.NCPDPScriptFormCode = S.NCPDPScriptFormCode
INNER JOIN table8 AS F ON S.FormName = F.FormName
GROUP BY PA.ProductID ,
S.ScriptFormID ,
F.Code ,
S.FormName
) FRM ON PR.ProductID = FRM.ProductID
GROUP BY PR.ePrescribingName ,
U.Strength ,
FRM.FormName ,
PR.DEAClassificationID
ORDER BY pr.ePrescribingName
SELECT LL.ProductID AS MedicationID ,
temp.MedicationName ,
temp.MedicationStrength ,
temp.MedicationForm ,
temp.DEASchedule ,
temp.NDCNumber ,
fs.[ReturnFormulary] AS FormularyStatus ,
copay.CopaTier ,
copay.FirstCopayTerm ,
copay.FlatCopayAmount ,
copay.PercentageCopay
FROM TempTherapeuticAlt temp
OUTER APPLY ( SELECT TOP 1
ProductID
FROM Product
WHERE ePrescribingName = temp.MedicationName
) AS LL
OUTER APPLY function1(#pid, LL.ProductID, #pbmid) AS fs
OUTER APPLY function2(LL.ProductID, #pbmid) AS copay
ORDER BY LL.ProductID
TRUNCATE TABLE TempTherapeuticAlt
END
GO
Here are a few:
You should have indexes for every column in a WHERE clause. See
your SQL language for how to do it.
Learn how to EXPLAIN PLAN and see what's slow.
Stored procedure languages are functional, not set based. Use JOIN and don't fall into the (n+1) query/iteration trap.
Understand how using certain functions force you to TABLE SCAN in a WHERE clause.

Resources