Click here to Skip to main content
15,889,840 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MS SQL SERVER 2008 - R2 Database

drop table #trial

create table #trial ( names varchar(10) ,
subject varchar(10) ,
marks varchar(10)
)

insert into #trial values ('ama' , 'maths' ,'A20')
insert into #trial values ('kay' , 'maths' ,'A30')
insert into #trial values ('kay' , 'geog' ,'A40')
insert into #trial values ('joh' , 'maths' ,'A50')
insert into #trial values ('joh' , 'geog' ,'A60')
insert into #trial values ('joh' , 'physics' ,'A70')
insert into #trial values ('ros' , 'english' ,'A80')

select * from #trial



Error

'Column name or number of supplied values does not match table definition.'


What am I doing wrong ?

What I have tried:

'Column name or number of supplied values does not match table definition.'
Posted
Updated 12-Jan-21 20:47pm

At a guess, you already have a temporary table called #trial, which has different columns than the ones shown.

When you try to execute the batch, SQL Server tries to compile it using the existing table definition. When it finds that the columns don't match, it produces an error and doesn't execute the batch.

Try selecting and running just the DROP TABLE #trial line. Then you should be able to execute the rest of your query.
 
Share this answer
 
Works for me:
SQL
create table #trial ( names varchar(10) ,
subject varchar(10) ,
marks varchar(10)
) 

insert into #trial values ('ama' , 'maths' ,'A20')
insert into #trial values ('kay' , 'maths' ,'A30')
insert into #trial values ('kay' , 'geog' ,'A40')
insert into #trial values ('joh' , 'maths' ,'A50')
insert into #trial values ('joh' , 'geog' ,'A60')
insert into #trial values ('joh' , 'physics' ,'A70')
insert into #trial values ('ros' , 'english' ,'A80')

select * from #trial
drop table #trial
Gives
names  subject       marks
ama    maths         A20
kay    maths         A30
kay    geog          A40
joh    maths         A50
joh    geog          A60
joh    physics       A70
ros    english       A80
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900