-4
INSERT INTO Buy
SELECT Title
    ,Type1
    ,Tedat
    ,DATEADD(DAY, - 2, DATEADD(YEAR, - 1, Tarikh))
    ,Descrip
FROM Buy
WHERE (
    Tarikh BETWEEN 2019-03-21
    AND 2020-03-19
)
Dale K
  • 25,246
  • 15
  • 42
  • 71
Rozbeh
  • 19
  • 3
  • 1
    The documentation on [constants / literals](https://learn.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql?view=sql-server-ver15) discusses how to write literals of all types. And stop the laziness. ALWAYS specify a column list in your insert statements. Do not create more work that needs to be done at a later date when the structure of the table is changed. – SMor Feb 16 '20 at 13:42

3 Answers3

2

You need to wrap your dates in quotes, as without them they are being evaluated as a series of integers, which isn't comparable with a date in your WHERE clause:

INSERT INTO Buy 
SELECT      Title,
            Type1,
            Tedat,
            DATEADD(DAY,-2,DATEADD(YEAR,-1,Tarikh)),
            Descrip 
FROM        Buy
WHERE       Tarikh BETWEEN '2019-03-21' AND '2020-03-19'
Rion Williams
  • 74,820
  • 37
  • 200
  • 327
0

You are missing quotes on the date

 INSERT INTO Buy SELECT  Title,Type1,Tedat,DATEADD(DAY,-2,DATEADD(YEAR,-1,Tarikh)),Descrip FROM Buy
                                WHERE(Tarikh BETWEEN '2019-03-21' AND '2020-03-19' )
zip
  • 3,938
  • 2
  • 11
  • 19
0

You need to wrap the date in quotes, like '2019-03-21' instead of 2019 - 03 - 21

INSERT INTO Buy
SELECT Title
    ,Type1
    ,Tedat
    ,DATEADD(DAY, -2, DATEADD(YEAR, -1, Tarikh))
    ,Descrip
FROM Buy
WHERE Tarikh BETWEEN '2019-03-21' AND '2020-03-19'

Besides, You ought to specify the column to avoid an unexpected error (insert into incorrect column or Just want to insert a number of columns instead of all)

INSERT INTO Buy(column1, column2,.. )
SELECT  Title, Tedat, .. 
FROM    Buy

Read the following post to have a better understanding

Insert into certain columns

Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56