In SQL server, I am trying to insert values from one table to another by using the below query:
delete from tblTable1
insert into tblTable1 select * from tb
for inserts it is always better to specify the column names see the following
DECLARE @Table TABLE(
Val1 VARCHAR(MAX)
)
INSERT INTO @Table SELECT '1'
works fine, changing the table def to causes the error
DECLARE @Table TABLE(
Val1 VARCHAR(MAX),
Val2 VARCHAR(MAX)
)
INSERT INTO @Table SELECT '1'
Msg 213, Level 16, State 1, Line 6 Insert Error: Column name or number of supplied values does not match table definition.
But changing the above to
DECLARE @Table TABLE(
Val1 VARCHAR(MAX),
Val2 VARCHAR(MAX)
)
INSERT INTO @Table (Val1) SELECT '1'
works. You need to be more specific with the columns specified
supply the structures and we can have a look