moonir01 moonir01 - 4 months ago 13
SQL Question

how can create table for Year and month

How can i have create table for year and month
table name :Year and insert data
2014 2015 2018 2019 2020 2021
and another table name
Month and inserting data
January,February,March,April,

Answer
CREATE TABLE Years(
 year int
);

CREATE TABLE Months(
month varchar(15)
);

DECLARE @cnt INT = 2014;

WHILE @cnt < 2021
BEGIN
   INSERT INTO Years(year) VALUES(@cnt);
   SET @cnt = @cnt + 1;
END;

For table Months you can add it one by one,

INSERT INTO Months(month) VALUES('JANURARY');
.
.
.
Comments