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
 General SQL Server Forums
 New to SQL Server Programming
 Simple (for you) update query question

Author  Topic 

jkeogh
Starting Member

2 Posts

Posted - 2010-01-12 : 10:24:50
Hi,

am hoping someone can help with what I presume (and hope) is a relatively simple question. (they always are when you know the answer!)

I need to update an existing table within a SQL 2005 DB
The table contains personal contact details, and I need to change a date field on approx 200 of the records (out of about 10,000).
I have a list of e-mail address in csv/txt format and I am looking for the code to do this...

update dbo.tablename
set date to 20/12/2010 (the updated date is the same for each record)
where emailcolumnname = look in my text file....

any clues, pointers would be greatly appreciated. I have had a mooch about trying to find the answer, but keep running in to Bulk Insert queries which didn't look quite right

many thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 10:33:31
something like below ( i dont know text file format so make sure you use appropriate col name)
update t
set t.date='2010-12-20'
from dbo.tablename t
inner join (select * from OpenRowset('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir={your directory}','select * from junk.txt'))t1
on t.emailcolumnname = t1.emailcol
Go to Top of Page

jkeogh
Starting Member

2 Posts

Posted - 2010-01-13 : 08:33:18
Hi,
thanks for that, it works perfectly. This has saved us about 12 hours of mind numbing data input!

thanks again
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-13 : 08:35:19
welcome
Go to Top of Page
   

- Advertisement -