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 2005 Forums
 Transact-SQL (2005)
 i want to insert records from one table to another

Author  Topic 

ontljoshi
Starting Member

13 Posts

Posted - 2007-04-03 : 08:50:20
hi,

i have 2 tables and scnario is like this...

sheet1
field1 field2
l1_cust_ref abc
l1_title mr

sifa_data
l1_cust_ref l1_title
abc mr


i want to transfer all the records from sheet1 to sifa_data but in here thig is like ...
what values field1 is haveing are field for sifa_data table and what fields2 having are values for sifadata field's values.

so kindly help me..in that.

thanks


om joshi

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-03 : 09:14:39
You are really going to have to supply more detail

Read the hint link in my sig



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ontljoshi
Starting Member

13 Posts

Posted - 2007-04-03 : 09:57:10
WHAT INFORMATION YOU WANT MORE LIKE....BECAUSE I AM BEGINEER IN SQL...JUST TRYING TO SORT THIS OUT...

MY TABLE1: SHEET1 HAS 2 FIELDS
1) FIELD1 AND FIELD2
2) FIELD1 HAS MANY VALUES LIKE L1_CUST_REF, L1_TITLE, AND SO ON
3) FIELD2 HAS MANY VALUES LIKE ABC,TITLE,AND SO ON

NOW I HAVE TABLE LIKE SIFA_DATA WHICH HAS SEVERAL FIELDS LIKE L1_CUST_REF, L1_TITLE, AND SO ON...

ACTUALLY FIELD1'S VALUES ARE THE ACTUAL FIELDS FOR SIFA_DATA TABLE AND FIELD2 VALUES ARE ACTUAL VALUES FOR SIFA_DATA'S FIELDS.

KINDLY DO NEEDFUL THANKS IN ADVANCE.

REGARDS
OM


om joshi
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2007-04-03 : 10:10:36
Not to sure what you are really trying to do,

Can you post the table schema at all?

However if you are trying to transfer certain columns data out of one table and insert just them into a second table something like the following will work

Example :

--create the two tables

create table tblOne
(
OneID int identity(1,1),
CustName varchar(30),
CustCity varchar(20),
CustTelephone Varchar(12)
)

Create Table tblSecond
(
SecondID int Identity(1,1),
CustName varchar(30),
CustTelphone varchar(30)
)

--The to just move one to the other you can use a select statement with an insert statement

Insert into tblSecond (CustName,CustTelephone)
Select CustName,CustTelephone
From tblOne

This will work for a quick transfer!!!

If that is what you are after I hope
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-03 : 10:23:07
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-03 : 10:32:52
Something along these lines?

Insert into Sifa_Data(L1_CUST_REF, L1_TITLE, ...)
Select
Case when Field1 = 'L1_CUST_REF' then Field2 else NULL end as L1_CUST_REF,
Case when Field1 = 'L1_TITLE' then Field2 else NULL end as L1_TITLE
...
From
SHEET1


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

ontljoshi
Starting Member

13 Posts

Posted - 2007-04-03 : 10:57:42
sorry to being a very nasty...harsh

but would you like to tell me what would be the end point if i you that i was trying
Select
Case when Field1 = 'L1_CUSTOMER_REFERENCE' then Field2 else NULL end as L1_CUSTOMER_REFERENCE,
Case when Field1 = 'L1_TITLE' then Field2 else NULL end as L1_TITLE
end;

but it gives me an error as its not proper

sorry once again.

regards,
om



om joshi
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-03 : 11:04:16
You should post some sample data with expected result as said here

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ontljoshi
Starting Member

13 Posts

Posted - 2007-04-03 : 11:58:15
quote:
Originally posted by harsh_athalye

Something along these lines?

Insert into Sifa_Data(L1_CUST_REF, L1_TITLE, ...)
Select
Case when Field1 = 'L1_CUST_REF' then Field2 else NULL end as L1_CUST_REF,
Case when Field1 = 'L1_TITLE' then Field2 else NULL end as L1_TITLE
...
From
SHEET1


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



this gives me syatax error...


i am trying this stuff in ms Access kindly help....because i have recovered the data from pascal based application and which total mess of files...and i dont have mastery as you guys have...

kindly do needful.

thanks
om

om joshi
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-03 : 12:00:43
Aha!! Now I see why my suggestion didn't work!

Why you are posting Access question in SQL 2005 forum? Post in appropriate forum to get correct answers.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

ontljoshi
Starting Member

13 Posts

Posted - 2007-04-03 : 12:06:22
quote:
Originally posted by harsh_athalye

Aha!! Now I see why my suggestion didn't work!

Why you are posting Access question in SQL 2005 forum? Post in appropriate forum to get correct answers.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



thanks but my logic was telling me that its related with quries thats why i have placed into this..part.

please get me an solution...it would be great help to me..

thanks.

om joshi
Go to Top of Page
   

- Advertisement -