I would like to merge two tables in mssql. The first Table have a task column. I would like to count the specific tasks and give the counted result to the second table to the AuftNr.
Do i need a subquery and group by to solve this ?
So far i have done this.
SELECT AB.PersNr as PersonalNumber
,CONVERT(char(10),DATEADD(DAY, AB.Tag, '30.12.1899'),126) AS Day
,CONVERT(char(10),DATEADD(SECOND, AB.Von, DATEADD(DAY, AB.Tag,
'30.12.1899')),108) AS [From]
,AB.Bis as [To]
,AB.Auftrag as Task
FROM AStpVonBis AB
LEFT JOIN Auftrag A ON (A.AuftNr = AB.Auftrag)
INNER JOIN Personen P ON (P.PersNr = AB.PersNr)
WHERE P.Abteilung = 170 AND AB.Tag = DATEDIFF(DAY, '30.12.1899', GETDATE())
AND AB.Bis = -2
SELECT A.AuftNr FROM Auftrag A
