| Author |
Topic |
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-09-15 : 14:12:49
|
| I know this is impossible, but if it makes sense to you, please help....At the same time I want todrop table testandselect * into test from testdoes this make sense?I can do it this wayselect * into temp from testdrop table testselect * into test from tempdrop table temp.... but I'm sure there's a better way? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-09-15 : 14:21:08
|
| I'm trying to update tables.So likesku,pricea,1b,2c,3and then I want to 'upload'a,3d,4and have the table read as a,3b,2c,3d,4The way I figured to do it was kind ofselect coalesce(new.sku,test.sku) as sku,coalesce(new.price,test.price) as priceinto test from test right join new on new.sku = test.skudoes this make sense? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-09-15 : 14:27:43
|
| how would that insert update statement look? Ultimatley I'm using .xls files to upload new information, and will be using them as linked servers. I cannot fathom how to use update or insert into statements to fix this. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ConradK
Posting Yak Master
140 Posts |
Posted - 2010-09-15 : 14:48:40
|
| I'm sure I'm making this WAAAYY harder than it needs to be. I'm using sql managment studio, and I can do anything my little heart desires. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2010-09-15 : 14:56:45
|
| Create a staging table first:SELECT * INTO NewTable FROM YourTable WHERE 1=0 (to get an empty shell)Import your data into NewTable using whatever method you want. You mentioned a linked server, so use that. I prefer bcp.exe as it is just so simple, to me at least.Then once you've got your data in the staging table:INSERT INTO YourTable (...)SELECT ...FROM NewTable nWHERE NOT EXISTS (SELECT * FROM YourTable y WHERE y.SomePKColumn = n.SomePKColumn)UPDATE ySET ... = n...., ...FROM YourTable y JOIN NewTable nON n.SomePKColumn = y.SomePKColumnTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
|