473,795 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use Excel modified date in Stored Procedure

code green
1,726 Recognized Expert Top Contributor
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
4 3246
ck9663
2,878 Recognized Expert Specialist
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 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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 Recognized Expert Top Contributor
Thanks ck9663. I will study your solution before implementing.
Particuarly the master..xp_cmds hell
Nov 11 '09 #5

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

Similar topics

18
10309
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 date and time, but my script is erroring. '-- Get login date and time cmdLoginDate = Date() cmdLoginTime = Time()
1
5036
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. Before I iterate through the recordset I instruct the browser that the content type is Excel using the following line: (Response.ContentType = "application/vnd.ms-excel") This works fine with Excel 2003 but with older versions (I tested Excel...
8
3261
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 this? Thanks, Jim.
22
15355
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 reproduce the behavior described below? For this example, I am using Excel 2002 and VS .NET 2002 and VB 6. MSFT KB article 304661 gives a trivial example of early and late binding to Excel from VB .NET. Note that there is a variable naming...
0
2331
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 & _ " WHERE (((IDU) Like 'czz*' Or (IDU) Like 'cam*' Or (IDU) _ Like 'szz*' Or (IDU) Like 'J*' Or (IDU) Like 'G*' Or (IDU) _ Like 'U*'))" & " ORDER BY IDU;"
2
11515
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: CAST(O.MYDATE AS CHAR(30)) When directly updating date fields in the main table, the logged value gets saved in the format YYYY-MM-DD as expected.
2
2821
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 "smalldatetime" fields. In my class for this table, when inserting new or saving a row in the table, both of these date values may possibly be empty. (ie I am allowing nulls on the db side... )
3
7639
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 the variable, I'm having problems. It is presenting the error listed below on the last line in my code section below. ERROR: Method Open of object Workbooks failed Dim xlApp As New Excel.Application Dim wbk As Excel.Workbook
1
1909
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 do I execute a SQL Stored procedure from Excel pulling through the variables?
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.