473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use Excel modified date in Stored Procedure

code green
1,726 Expert 1GB
Within a stored procedure I am creating a table from an Excel spreadsheet
Expand|Select|Wrap|Line Numbers
  1. /*Create tmp table from XLS*/
  2. SELECT * INTO tmp_cons FROM
  3. OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;
  4. Database=\\[server]\path\to\Excel\spreadsheet.xls',
  5. 'SELECT * FROM [sheet1$]')
Then joining this table to update another with new products
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO consum_stk (part,qty)
  2. SELECT tmp_cons.Part,Stock FROM tmp_cons
  3.     LEFT JOIN consum_stk 
  4.     ON tmp_cons.Part = consum_stk.part
  5. WHERE consum_stk.part IS NULL
consum_stk also has a last_updated column with GETDATE() as default.
Is it possible to use the Excel file 'modified' date property to populate this field
Nov 9 '09 #1

✓ answered by ck9663

Yes. I'm sure there are a number of other ways of doing it. Until someone suggest something else try the following pseudo-code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @tblDirCheck table (RowNum int IDENTITY(1,1),CmdResult varchar(max))
  3.  
  4. set @tsql = 'dir \\[server]\path\to\Excel\spreadsheet.xls /TW'
  5.  
  6. insert into @tblDirCheck(cmdresult)
  7.   exec @ErrorNumber = master..xp_cmdshell @tsql         
  8.  
  9.  
Now you'll have a single row on your table variable. Parse the cmdresult column to get your modified date/time. Just be careful, if one of the sheets was modified, the date/time will change even if your target sheet were not modified at all.

Happy Coding!!!


--- CK

4 3232
ck9663
2,878 Expert 2GB
Yes. A default value will be used if you did not specify any value into a column when the record was created. You just have to get the property of file from the OS side to get the value of the modified date.

Good luck!!!

--- CK
Nov 9 '09 #2
code green
1,726 Expert 1GB
Thanks for replying
You just have to get the property of file from the OS side to get the value of the modified date.
This is the bit I am stuck on.
Can this be done from a stored procedure?
Nov 9 '09 #3
ck9663
2,878 Expert 2GB
Yes. I'm sure there are a number of other ways of doing it. Until someone suggest something else try the following pseudo-code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @tblDirCheck table (RowNum int IDENTITY(1,1),CmdResult varchar(max))
  3.  
  4. set @tsql = 'dir \\[server]\path\to\Excel\spreadsheet.xls /TW'
  5.  
  6. insert into @tblDirCheck(cmdresult)
  7.   exec @ErrorNumber = master..xp_cmdshell @tsql         
  8.  
  9.  
Now you'll have a single row on your table variable. Parse the cmdresult column to get your modified date/time. Just be careful, if one of the sheets was modified, the date/time will change even if your target sheet were not modified at all.

Happy Coding!!!


--- CK
Nov 9 '09 #4
code green
1,726 Expert 1GB
Thanks ck9663. I will study your solution before implementing.
Particuarly the master..xp_cmdshell
Nov 11 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
8
by: JIM.H. | last post by:
Hello, I am calling a stored procedure to update my table. If one of the date on the screen left empty, I need to send date as null. Since MyDate=”” gives error in asp.net, how should I do...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
0
by: franjorge | last post by:
Hi, I have created two stored procedures via VB using this code: sql = "CREATE PROC " & nombre_proc & " AS SELECT *" & _ " From MBM_PUNTOS_SCE_SIN_COINCIDIR_SIEGE_FALTA_PM_NE_" & mes & _ "...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
2
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple...
3
dbushcmohle
by: dbushcmohle | last post by:
Hello, I am having problems exporting a stored procedure's results to an Excel file... I've done this many times successfully, but never had to introduce a variable. Now that I've introduced...
1
by: flickimp | last post by:
Hi I have a stored procedure on SQL Server 2000 called: .Capacity_Planning.dbo.sp_flickimp_test I have an Excel Sheet with the 2 paramters for the Stored procedure in cells A1 and B1. How...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.