Create a table in your database that has the desired schema. It doesn't have to contain any data. (Allowing NULL values will accommodate months that don't have 31 days.)
CREATE TABLE SCHEMA_TEMPLATE
(
NAME nvarchar(255) NULL,
Day1 DATE NULL,
...
Day31 DATE NULL
) ON PRIMARY;
Then, write a stored proc that will create the desired data table that has the same schema as the SCHEMA_TEMPLTE table. Pass the desired table name to it (for instance, "May2018"):
CREATE PROCEDURE dbo.sp_CreateTableForMonth
@tableName nvarchar(50)
AS
BEGIN
DECLARE @query nvarchar(MAX) =
'SELECT TOP 0 * INTO '+@tableName+' FROM dbo.SCHEMA_TEMPLATE';
EXEC sp_executesql @query;
END
After that, it's a simple matter to put your data into the table from your code.
===================================
I would revisit your schema as well. Seems to me there might be a better way to represent the data, such as just putting all the data into the same table, and using a
MERGE
command to update the table. This beats having one table for every month...