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.
| Author |
Topic |
|
erodzen
Starting Member
2 Posts |
Posted - 2009-01-24 : 15:24:43
|
| This is probably very very simple for any T-SQL experts, but I have only just begun to learn SQL. I have an Excel spreadsheet which is a list of items that I want to change one column for. The spreadsheet has the PrimaryID of the items. It is a subset of all the items. I can create a CSV file from the spreadsheet. I want to read from that CSV file and update the records that are listed in the CSV file. Can someone write me a quick and easy SQL command to do what I need?Table is ITPRICE, want to set ITP_SCOMM = 1, for all records which match the PrimaryID in products.csv. (Do I need a header row in the csv file?) Here is what I tried: (am I close?)UPDATE ITPRICESET ITP_SCOMM = 1 FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0', 'Text;Database=C:\;', 'SELECT * FROM [products.csv]') AS Pwhere P.PrimaryID=ITPRICE.PrimaryID |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-25 : 04:50:17
|
you're close. yup you need header in csvUPDATE iSET i.ITP_SCOMM = 1 FROM ITPRICE iJOIN(SELECT fields...FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0', 'Text;Database=C:\;', 'SELECT * FROM [products.csv]') AS P)AS RON R.PrimaryID=ITPRICE.PrimaryID |
 |
|
|
erodzen
Starting Member
2 Posts |
Posted - 2009-01-26 : 10:48:57
|
| Thanks so much for trying to help me!!!!Tried this as shown and got errors until I made the following changes. Then it updates every row - does not use the CSV file info at all. What have I done wrong?(CSV file has one column with header PID)UPDATE ITPRICESET ITP_SCOMM = 1 FROM ITPRICE iJOIN(SELECT PIDFROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0', 'Text;Database=C:\;', 'SELECT PID FROM [products.csv]') AS P)AS RON R.PID=ITPRICE.ITP_PrimaryID |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-27 : 00:52:12
|
| [code]UPDATE iSET i.ITP_SCOMM = 1 FROM ITPRICE iJOIN(SELECT PIDFROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0', 'Text;Database=C:\;', 'SELECT PID FROM [products.csv]') AS P)AS RON R.PID=ITPRICE.ITP_PrimaryID[/code] |
 |
|
|
|
|
|