vendredi 1 juillet 2016
Sql query to retrieve data in described format
Struggling to conceptualize this query. Any help will be appreciated.
Dataset
Table: Audit
Date |Action |PackageId
1/1/15 |Active |1
1/2/15 |DeActive|1
11/3/16|Update |2
12/3/16|Update |2
13/3/16|Update |2
14/3/16|Update |2
Table: Package
Id|Name
1 |package1
2 |package2
Table: Item
Id|ItemName|PackageId
1 | item1 |1
2 | item2 |1
3 | item3 |1
4 | item4 |2
5 | item5 |2
The relationship between these tables is Audit.PackageID Is foreign key to Package.Id and Item.PackageId is foreign key to Pacakge.id
For the above data, I want to generate a report like this
Package.Name|Item.ItemName|Audit.Date|Audit.Action
package1 | item1 | 1/1/15 | Active
package1 | item2 | 1/2/15 | DeActive
package1 | item3 | NULL | NULL
package2 | item4 | 11/3/16 | update
package2 | item5 | 12/3/16 | update
package2 | NULL | 13/3/16 | update
package2 | NULL | 14/3/16 | update
basically the item or audit information is not duplicated and package information is duplicated if item/audit information is more than number of packages. Hope it makes sense.
I basically need to write a stored procedure that will return a dataset as described above. This result is then fed into a report parser that will replace all NULL with blanks and generate an Excel report.
The database is SQL-Server-2000.
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire