I have a data set for Users per minute over an hour that only includes non zero entries, I would like to update the table so that it includes all minuets. Currently my first would like like this if I had inserted it instead of imported it:
`
CREATE TABLE table1 (minute INT NOT NULL, users INT NOT NULL);
INSERT INTO table1 (minute, users) VALUES (32,1);
INSERT INTO table1 (minute, users) VALUES (40,1);
INSERT INTO table1 (minute, users) VALUES (41,1);
INSERT INTO table1 (minute, users) VALUES (51,1);
INSERT INTO table1 (minute, users) VALUES (52,1);
`
I would like the 55 other minutes in an hour to show up along with the a 0 users. the range is (0-59)
to help that I created a second table
`
CREATE TABLE m_fix
(minute INT NOT NULL, users INT NOT NULL);
INSERT INTO m_fix (minute, users) VALUES (0,0);
INSERT INTO m_fix (minute, users) VALUES (1,0);
INSERT INTO m_fix (minute, users) VALUES (2,0);
INSERT INTO m_fix (minute, users) VALUES (3,0);......
`
I was able to do a a select join to display the information I wanted with this code:
`
SELECT
m_fix.minute,
Case
When table1.users IS NULL THEN m_fix.users
ELSE table1.users
END AS users
FROM m_fix
LEFT JOIN table1 ON m_fix.minute=table1.minute;
`
But I want to update the my table1 instead of running a query since I am eventual going to export this data elsewhere. to do that I made this code:
`
INSERT INTO dbo.table1
SELECT dbo.fix.minute, dbo.fix.users
FROM dbo.fix
LEFT JOIN dbo.table1
ON dbo.fix.minute=dbo.table1.minute
Where dbo.fix.minute!= dbo.table1.minute;
Select * From dbo.table1;
`
and it just have me my old table 1 with 5 rows
This is only my test case, I have days more data to deal with so I would like one commanded that I can run on each new table I import that adds all the missing minuets with user = 0