Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default query external database

i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very simple...e.g.

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple joins
and conditions, etc), however when i paste the query into the macro, the
formatting causes issues (e.g. the query text is highlighted in red). how do
i incorporate the new query? i tried using _ to connect, but at one point i
received a message that too many were used.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default query external database

hi
if high lighted in red then you have a syntax problem
post your macro.

regards
FSt1

"joemeshuggah" wrote:

i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very simple...e.g.

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple joins
and conditions, etc), however when i paste the query into the macro, the
formatting causes issues (e.g. the query text is highlighted in red). how do
i incorporate the new query? i tried using _ to connect, but at one point i
received a message that too many were used.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default query external database

the problem is when i copy and paste the query into the macro...for example

query = "select * from mytbl inner join mytbl2 on mytbl.a=mytbl2.a" would
work fine...

but when copying and pasting the query as written into the macro, the red
text appears (a quote appears automatically after select *, inner join mytbl2
on and mytbl.a=mytbl2.a appear in red and a quote automatically appears after
mytbl.a=mytbl2.a).

query = "select * "
from mytbl
inner join mytbl2 on
mytbl.a=mytbl2.a"


is it possible to paste the query without reformatting it...and if not, how
do you reformat to ensure there are no syntax errors? here is an example of
how the query is formatted:

select *

from

mytbl

inner join mytbl2 on
mytbl.a=mytbl2.a


"FSt1" wrote:

hi
if high lighted in red then you have a syntax problem
post your macro.

regards
FSt1

"joemeshuggah" wrote:

i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very simple...e.g.

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple joins
and conditions, etc), however when i paste the query into the macro, the
formatting causes issues (e.g. the query text is highlighted in red). how do
i incorporate the new query? i tried using _ to connect, but at one point i
received a message that too many were used.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default query external database

hi
i don't think you understand. you are just posting the SQL. Post the entire
query. with red text, that is invalid syntax. we need to see more than just
the red text.
there is a lot more to it that just "query =.....". we need to see all of
"the other stuff". help us help you. post all of your macro.
it's 3am in atlanta. i am about to crash. i will search for you reply
tomorrow. god bless.
regards
FSt1


"joemeshuggah" wrote:

the problem is when i copy and paste the query into the macro...for example

query = "select * from mytbl inner join mytbl2 on mytbl.a=mytbl2.a" would
work fine...

but when copying and pasting the query as written into the macro, the red
text appears (a quote appears automatically after select *, inner join mytbl2
on and mytbl.a=mytbl2.a appear in red and a quote automatically appears after
mytbl.a=mytbl2.a).

query = "select * "
from mytbl
inner join mytbl2 on
mytbl.a=mytbl2.a"


is it possible to paste the query without reformatting it...and if not, how
do you reformat to ensure there are no syntax errors? here is an example of
how the query is formatted:

select *

from

mytbl

inner join mytbl2 on
mytbl.a=mytbl2.a


"FSt1" wrote:

hi
if high lighted in red then you have a syntax problem
post your macro.

regards
FSt1

"joemeshuggah" wrote:

i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very simple...e.g.

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple joins
and conditions, etc), however when i paste the query into the macro, the
formatting causes issues (e.g. the query text is highlighted in red). how do
i incorporate the new query? i tried using _ to connect, but at one point i
received a message that too many were used.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default query external database

your query may be split over sevaral lines...its impossible to tell unless
you post the exact code.

however you have two options he

1) use one line
query = "select * from mytbl inner join mytbl2 on mytbl.a=mytbl2.a"

or
(2) concatenate
query = "select * from mytbl inner" _
& "join mytbl2" _
& "on mytbl.a=mytbl2.a"

note here the underscore "_" which tells the VBA compiler that the line
follows on

"joemeshuggah" wrote in message
...
the problem is when i copy and paste the query into the macro...for
example

query = "select * from mytbl inner join mytbl2 on mytbl.a=mytbl2.a" would
work fine...

but when copying and pasting the query as written into the macro, the red
text appears (a quote appears automatically after select *, inner join
mytbl2
on and mytbl.a=mytbl2.a appear in red and a quote automatically appears
after
mytbl.a=mytbl2.a).

query = "select * "
from mytbl
inner join mytbl2 on
mytbl.a=mytbl2.a"


is it possible to paste the query without reformatting it...and if not,
how
do you reformat to ensure there are no syntax errors? here is an example
of
how the query is formatted:

select *

from

mytbl

inner join mytbl2 on
mytbl.a=mytbl2.a


"FSt1" wrote:

hi
if high lighted in red then you have a syntax problem
post your macro.

regards
FSt1

"joemeshuggah" wrote:

i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very
simple...e.g.

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple
joins
and conditions, etc), however when i paste the query into the macro,
the
formatting causes issues (e.g. the query text is highlighted in red).
how do
i incorporate the new query? i tried using _ to connect, but at one
point i
received a message that too many were used.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default query external database

If you are getting an error regarding too many _ try building the SQL
like this.

strSQL = "SELECT * "
strSQL = strSQL & "FROM mytbl "
strSQL = strSQL & "INNER JOIN mytbl2 ON mytbl.a=mytbl2.a;"

You can also use this syntax to make the code more readable, but be
careful to add spaces where needed for the SQL.

On Jun 19, 9:23*pm, joemeshuggah
wrote:
i have a macro that automatically runs a query in an external database
(teradata) and puts the results in excel...the query is very simple...e.g..

query = "select * from mytbl"

i would like to use the same idea for more complex queries (multiple joins
and conditions, etc), however when i paste the query into the macro, the
formatting causes issues (e.g. the query text is highlighted in red). *how do
i incorporate the new query? *i tried using _ to connect, but at one point i
received a message that too many were used.


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
Tool bar: Data/Import external data/New database query Daniel Setting up and Configuration of Excel 3 February 28th 08 08:40 AM
database query not showing foxpro database How I import data mangat New Users to Excel 1 June 24th 07 03:31 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 1 November 29th 05 01:44 PM
Anyone Else Use Database Query to Query Another Sheet in the Same Excel Workbook? jocke Excel Discussion (Misc queries) 0 November 28th 05 06:37 PM


All times are GMT +1. The time now is 03:54 AM.

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

About Us

"It's about Microsoft Excel"