Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing data from SQL database - Variables

Does anyone know if it is possible to import data from an SQL databas
using a given variable.

I.e. the user inputs a date they wish to get the data from (i.e. fro
1st Novemeber ). This date is then stored as a date variable. Usin
this variable is it possible to import data from the database give
this date scale?

for example:

Dim dat as date


(code for importing data using querytables.add)

.CommandText = ARRAY(SELECT table1.name, table1.address, table1.date
FROM databasey.table1 WHERE table1.date = ts '2003-11-01 00:00:01'})

Is it possible to replace the "ts '2003-11-01 00:00:01" with th
varibale 'dat'. (I am also unsure what the 'ts' bit means) If it i
possible what format does the date have to be in?

Stuck in a rut!!!!!
:confused

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Importing data from SQL database - Variables

Dani,

It should be straightforward to replace the date with a variable. Only thing
to watch is that the SQL statement expects strings, so the date should be
formatted as a string, like this

CommandText ="SELECT table1.name, table1.address, table1.date FROM
databasey.table1 WHERE table1.date = """ & Format(myDate,"dd-mmm-yyyy") &
"""

Can't hrelp you withthe ts I am afraid.
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"daniB " wrote in message
...
Does anyone know if it is possible to import data from an SQL database
using a given variable.

I.e. the user inputs a date they wish to get the data from (i.e. from
1st Novemeber ). This date is then stored as a date variable. Using
this variable is it possible to import data from the database given
this date scale?

for example:

Dim dat as date


(code for importing data using querytables.add)

CommandText = ARRAY(SELECT table1.name, table1.address, table1.date
FROM databasey.table1 WHERE table1.date = ts '2003-11-01 00:00:01'})

Is it possible to replace the "ts '2003-11-01 00:00:01" with the
varibale 'dat'. (I am also unsure what the 'ts' bit means) If it is
possible what format does the date have to be in?

Stuck in a rut!!!!!



---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Importing data from SQL database - Variables

Thanks Bob,

I think I understand now!

Dani:

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing data via an external database query rtiguy Excel Discussion (Misc queries) 3 October 13th 08 08:02 PM
Importing Data via Database Query Franklin Smith Excel Discussion (Misc queries) 0 October 17th 07 05:37 PM
when importing data from external database does not load into wor. Hari[_2_] Excel Discussion (Misc queries) 0 March 19th 07 03:52 PM
Problem importing data into sql server database Me Excel Discussion (Misc queries) 1 January 27th 06 01:51 AM
Importing Data from an Access Database Including a Hyperlink Colum B.C.Lioness Excel Discussion (Misc queries) 0 May 16th 05 05:26 PM


All times are GMT +1. The time now is 01:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"