Add New Columns that Repeat Min and Max Dates I have a table that has a column for the Line # and a column for the date that Line # was invoiced for.  I want to create two new columns: one column that repeats the Min date for the Line # and another column that repeats the Max date for the Line #.

Here is the original table:


Here is what I want the result to be:
You can use a SQL Server windowing function like this:

--demo setup
Declare @t table ([month] date, linenumber int)
insert into @t([month],linenumber) values
('12/30/2018',123), ('1/29/2019',123),
('7/30/2018',789), ('8/29/2019',789)

SELECT [month]
    ,linenumber
    ,min([month]) OVER (PARTITION BY linenumber) AS mininvoicedate
    ,max([month]) OVER (PARTITION BY linenumber) AS maxinvoicedate
FROM @t




| month      | linenumber | mininvoicedate | maxinvoicedate |
|------------|------------|----------------|----------------|
| 2018-12-30 | 123        | 2018-12-30     | 2019-01-29     |
| 2019-01-29 | 123        | 2018-12-30     | 2019-01-29     |
| 2018-07-30 | 789        | 2018-07-30     | 2019-08-29     |
| 2019-08-29 | 789        | 2018-07-30     | 2019-08-29     |




For more information about SQL Server windowing functions, check out the documentation in this post SELECT - OVER Clause (Transact-SQL)