SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Howto. ..Load 2 columns from excel file into table with corresponding columns ?


Howto. ..Load 2 columns from excel file into table with corresponding columns ?

Author
Message
johnnyrmtl
johnnyrmtl
Say Hey Kid
Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)

Group: General Forum Members
Points: 705 Visits: 429
Hello,

Since I'm not a programmer and hopefully there's a simply way...
I need to load one column from an excel file into a database table while trying to match the corresponding columns Unsure

1) I have 3 columns in the excel with a server , account and account description column
2) The database table has these same columns but the account description is BLANK
3) I need to populate the account description from the excel from the corresponding row.

I hope i'm clear

many thx
Steve Jones
Steve Jones
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: Administrators
Points: 144730 Visits: 19424
Simple way: Use the import wizard in SSMS to load the data into a temp table.

Then use a query to match up the data. If you temp table is MyStage and your regular table is Accounts, I'd run a select first

select
a.server
, a.account
, a.description
, b.server
, b.account
, b.description
from accounts a
inner join Mystage b
on a.server = b.server
and a.account = b.account



This will show you the contents of your account and staging tables as they match up. If this is right, you can update the account table like this:

update a
set a.description = b.description
from accounts a
inner join Mystage b
on a.server = b.server
and a.account = b.account



Then use the first statement to check things.

Drop the staging table when you are done.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
johnnyrmtl
johnnyrmtl
Say Hey Kid
Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)Say Hey Kid (705 reputation)

Group: General Forum Members
Points: 705 Visits: 429
Much appreciated !

I actually tried it the import data wizard and recreated the table with the necessary columns by loading all the respective rows... now I will just work from there instead of comparing the rows.

Will also try it the way you mention

thx
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search