Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 insert values of a column from one table to column

Author  Topic 

picatshou
Starting Member

12 Posts

Posted - 2014-04-19 : 17:49:17
hievery body i want to insert the values of a column from one table to the column in one other table
i don't want to specify values because there are many values in the column how can i do that so ?

part of table one :
NAME number
jim 12
tim 16
ketty 19


table 2:
identif num class


i want to insert values in columns name and number from table 1 into identif and num of table 2

Thanks a lot for any answer

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 18:03:07
insert t2 (identif, num)
select name, number
from t1


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

picatshou
Starting Member

12 Posts

Posted - 2014-04-19 : 18:11:03
thnx but it shows error in clause from !
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 18:19:57
What is the error - you need to substitute your table name for t1. Maybe enclose identifiers in square brackets and make sure you have the correct case if you are case sensitive.

You are using sql server?

insert [table 2] ([identif], [num])
select [name], [number]
from [Table one]

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

picatshou
Starting Member

12 Posts

Posted - 2014-04-19 : 18:25:09
yes i am using sql server 2008 now it shows the message :
this instruction is not a request !
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 18:27:42
How are you executing it?

Try
select 1

and see what happens

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 18:31:19
A search for that error message brings back no results which makes me think something odd is going on.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

picatshou
Starting Member

12 Posts

Posted - 2014-04-19 : 18:34:54
when i execute one other it works !

in fact the select is from a table excel i clic import then sql request so table 2 is an axcel file and table 2 is sqlserver table
one other remarque is that there is no into in your request so it shows error insert into !
and then when i put into it shows it is not a request i don't know what i will do ?!
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 19:11:54
the into is optional in an sql server query statement - that's why I ask how you are executing this.

try

select top 10 *
from [table one]

How are you connecting to the excel file - a linked server?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

picatshou
Starting Member

12 Posts

Posted - 2014-04-19 : 19:17:05
this request works !but the other one no!
to connect to excel by right click on the name of data base then i choose (tâches ->importer des données)


Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2014-04-19 : 19:31:57
That will import data into a table. You then need to use that table in a query to insert into your final table.

Another option is to use ssis (which is what your import is doing) to import into your final table.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -