- Specify the column -tablesNamesColumn- you want its data to be the names of the tables/sheets
- import the main sheet to MSSQL
- Select distinct values from the tablesNamesColumn
- Create a table and name it "TablesNames": CREATE TABLE [dbo].[TablesNames]([id] [int] IDENTITY(1,1) PRIMARY KEY,[Table_Name] [nvarchar](255) NOT NULL,)
- insert the tables names in the table which contains the tables names insert into
TablesNamesSELECT distinct tablesNamesColumnFROM [AllSheets]
- Now you need to loop inside the tables names and create tables in the same formatDECLARE @LoopCounter INT , @MaxTablesNamesId INT,@TableName NVARCHAR(100)SELECT @LoopCounter = 0 , @MaxTablesNamesId = count(*)FROM TablesNamesWHILE ( @LoopCounter IS NOT NULLAND @LoopCounter <= @MaxTablesNamesId)BEGINSELECT @TableName = Table_Name FROM TablesNamesWHERE id = @LoopCounter-- PRINT @TableNameSELECT @LoopCounter = min(id) FROM TablesNamesWHERE id > @LoopCounterdeclare @q nvarchar(max) = 'drop table ['+@TableName+'];SELECT * INTO ['+@TableName+']FROM [delme]WHERE Institution = N'''+ @TableName +''';'exec (@q)END
- Use the following steps to export the data to Excel 97-2003 file, because I tried Excel 2010 and 2016, the only one works fine is 97-2003
Saturday, 21 September 2019
How to export one table or sheet to multiple tables or sheets
If you have one excel sheet or table and you want to export it to multiple sheets or tables use the following steps:
Subscribe to:
Posts (Atom)