Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from temptbl that is subset of main
Message
From
02/06/2012 12:52:20
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01545128
Message ID:
01545156
Views:
42
Thanks Sergey. I did think of that but it means either generating a new set of identity keys ( not sure if in the long run that will be problem or not on this table ) or I guess turning off indentity while doing the insert ( never did that on the fly so don't even know if that is possible.) I also considered doing the CSV import into a table that is actually there in the database with exactly the same structure which I truncate before every import and then doing the insert into the main table from there.

Since you haven't suggested a magic bullet version of the code below <g> I will assume I should just stop being lazy and write the update properly, specifiying all the possibly changed columns.

( which as I think of it are only about half of them.)

It's funny , coming from a heavily procedural mindset in VFP and C# I didn't realize the power of set based thinking until this project pushed me out of my comfort zone and I started to learn and do things in T SQL I had not attempted before.

Now I see why Denis Gobo and some of the other guys I work with are so comfortable accomplishing some pretty cool stuff on the back end when my first impulse is to start looping through records in my business objects.

in this case the alternative - using BIS 2005 which I am running on a VM where the data visualizers won't work - would have meant doing some kludgy ADO stuff in the VBA script objects. This T SQL approach has not only made my team happy but has let me do one of my favorites things : learning cool stuff on other people's dime <bg>



>You can delete the batch and insert it as a whole from the temp table.
>
>
>>I am inserting about a hundred rows of about 80 columns from a csv into a sql table. they all have an identity PK and a batchid that identifies them as a set
>>
>>I another procedure I am selecting all the rows where batchid = @batchid into #temp
>>
>>I am making a lot of changes to these rows but never deleting or adding any and it seems more convenient to work with this subset rather than have to qualify everything with batchid if I work directly against the table.
>>
>>But when I get done i want to basically replace the rows in the table with data in the temp table.
>>
>>I know I can do that as shown below, but is there a better way that does not require writing 80 column matches? I tried a.* = b.* but it doesn't seem to like that.
>>
>>
>>UPDATE a
>>set 
>>a.fld1 = b.fld1,
>>a.fld2 = b.fld2,
>>...etc
>>FROM maintable a
>>inner join #temp b
>>where a.pk = b.pk
>>
>>
>>TIA


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform