SQL Server : How to fetch data from dynamic multiple tables?

后端 未结 1 1215
盖世英雄少女心
盖世英雄少女心 2021-01-26 11:02

Using SQL SERVER.

The database contains data from different years, somehow I want to fetch all the data (all the years) and show to the user, for example, database conta

1条回答
  •  余生分开走
    2021-01-26 11:58

    Create procedure in this Below steps you need to follow.

    • Create table Common_Table with same one structure which all your table like records_2000_02 and others.
    • Use loop or cursor for all records you get from information_schema which match your table name
    • Create dynamic sql like ' Insert into your Common_Table select * from ' + Table_name that you get from Information_schema.
      • Then you get all your data in one table Common_Table

    0 讨论(0)
提交回复
热议问题