If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Updating Date in SQL Query (Excel Connections OLE DB Query)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-12, 09:59
SQLGurl SQLGurl is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Red face Updating Date in SQL Query (Excel Connections OLE DB Query)

Hello,

I am running a query that returns transactions that were done at a given point.

For this, I am using the"connections" part of Excel.

I have created a workbook connection

Connection type : OLE DB Quert

Command Type: SQL

Command Text:

Select
t.SP_ID AS Salesperson
,sum(CASE t.Transaction_Date WHEN '01/05/2012' THEN (abs(t.Transaction_Units) * t.Transaction_Price

etc

It runs finds and returns my data into a table in Excel.

However, I need to manually update the relevant date in the Command Text.

Is there a way that the connection automatically updates the date. as indicated in a cell in Excel, or maybe t-1 given that the file updates automatically every time I open?

MAny thanks
Reply With Quote
  #2 (permalink)  
Old 01-09-12, 12:58
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You can obtain today's date in SQL using the GetDate() function.

Code:
SELECT GetDate() As todays_date_and_time
     , DateAdd(dd, DateDiff(dd, 0, GetDate()), 0) As todays_date_no_time
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 01-09-12, 12:59
blindman blindman is online now
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,733
No.
You should not be trying to update database date from Excel, anyway. Excel is acceptable for viewing data, but it is not appropriate as a user-interface for transaction processing.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
Reply

Tags
connections, excel, sql, sql date update

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On