SQL Server : Columns to Rows

后端 未结 6 1138
孤城傲影
孤城傲影 2020-11-22 03:11

Looking for elegant (or any) solution to convert columns to rows.

Here is an example: I have a table with the following schema:

[ID] [EntityID] [Indi         


        
6条回答
  •  情深已故
    2020-11-22 03:30

    DECLARE @TableName varchar(max)=NULL
    SELECT @TableName=COALESCE(@TableName+',','')+t.TABLE_CATALOG+'.'+ t.TABLE_SCHEMA+'.'+o.Name
      FROM sysindexes AS i
      INNER JOIN sysobjects AS o ON i.id = o.id
      INNER JOIN INFORMATION_SCHEMA.TABLES T ON T.TABLE_NAME=o.name
     WHERE i.indid < 2
      AND OBJECTPROPERTY(o.id,'IsMSShipped') = 0
      AND i.rowcnt >350
      AND o.xtype !='TF'
     ORDER BY o.name ASC
    
     print @tablename
    

    You can get list of tables which has rowcounts >350 . You can see at the solution list of table as row.

提交回复
热议问题