Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > SQL Command Line Consolidation
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 1st August 23:03
g. bensonjzÊj.±Ø¬rë,Љìš+¢ÊµÊ&
External User
 
Posts: 1
Default SQL Command Line Consolidation



My primary objective is to link an Excel worksheet with an SQL table, and then update the LOG_SOURCE column of the SQL table with the values from the Excel worksheet (using ITEMNO as the link). I'd like to consolidate the following code or simplify the entire process, if possible. Here is a brief description of my actual data

Excel File name = inventory.xl
File location = C:\Do***ents and Settings\POS\Desktop\inventory.xl
Excel current worksheet sample (both columns are 16 character fields)

ITEMNO LOG_SOURC
A1 13110 B1 White 3 Rin
A2 13111 B2 White 3 Rin
A3 13112 B3 09/09/0
A4 13113 B4 09/09/0
A5 13114 B5 09/09/0

SQL Table Name = ITEM
SQL current table sample (both columns are 16 character fields)

ITEMNO LOG_SOURC
1311
1311
1311
1311
1311

I apologize in advance for my limited SQL experience, but here is the code that I've collected thus far to perform the link

EXEC sp_addlinkedserver 'ExcelSource'
'Jet 4.0'
'Microsoft.Jet.OLEDB.4.0'
'C:\Do***ents and Settings\POS\Desktop\inventory.xls'
NULL
'Excel 5.0

(not sure what I should change Excel version name to if I'm using Microsoft Office Excel 2003

EXEC sp_addlinkedsrvlogin 'ExcelSource', 'false

EXEC sp_tables_ex ExcelSourc
EXEC sp_columns_ex ExcelSourc

SELECT
FROM ExcelSource...Sheet1

CREATE TABLE test_exce
(id int
name varchar(255)
G

INSERT INTO test_exce
SELECT
FROM ExcelSource...Sheet1

SELECT
FROM test_exce

/* Now define two ranges in Excel on the 2nd sheet as tables *
/* Select the range, Insert->Name->Define *
/* Note: sp_tables_ex does not recognize the defined tables *
/* We can still refer to the tables ********ly *

EXEC sp_tables_ex ExcelSourc
EXEC sp_columns_ex ExcelSourc

SELECT
FROM ExcelSource...Table

SELECT
FROM ExcelSource...Table

(I wonder if I could avoid defining table ranges to save a step or two and simply use column ranges -in other words, what commands could we eliminate by using Sheet1 A1:A5 & Sheet1 B1:B5 ?

(what part of your code triggers the actual update of the SQL server's LOG_SOURCE column with the Excel values?

Here is the code I've collected thus far to perform the update

update Items set log_source = t1.log_sourc

update item
se
items.LOG_SOURCE = t1.LOG_SOURC
from t
inner join Item
on items.ItemNo = t1.ItemN

Also, does DTS come as part of MSDE & if so, how do I access it? Would I save any time by using DTS rather than the procedures above

Thank you in advance for your time and expertise.
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666