samedi 25 juin 2016

How can i get table name as column from the current table in sql server

I'm trying to find a way to get the "table name" as column from the current table in SQL Server 2012 SELECT 'School1.dbo.Person', Age, COUNT(Age) FROM School1.dbo.Person GROUP BY Age UNION ALL SELECT 'School2.dbo.Person', Age, COUNT(Age) FROM School2.dbo.Person GROUP BY Age As I'm hard-coding the table name in first column of each select statement, it doesn't make much sense, is there way I could get the table name in first column dynamically? Appreciate your thoughts! RAP

Aucun commentaire:

Enregistrer un commentaire