WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

View SQL Query-String in Excel

 
   Home -> Office -> Query DAO RSS
Next:  Copying Multiple files in one file Macro - Liz  
Author Message
Dagmar

External


Since: Jun 13, 2006
Posts: 6



(Msg. 1) Posted: Thu Mar 08, 2007 1:49 am
Post subject: View SQL Query-String in Excel
Archived from groups: microsoft>public>excel>querydao (more info?)

Hi!

We are using an application which creates Excel Pivot tables. These Pivot
tables get their data from an SQL-Server. I need to see (maybe edit) the
SQL-Query string. From your newsgroup I learned that the commands "?
ActiveCell.QueryTable.CommandText" etc. would be the solution to my problem.

However, when I run them in the immediate window I geht "Run-time error
1004" Application-defined or object-defined error".

Do you have any idea what is going wrong?

Dagmar
Back to top
Login to vote
Dick Kusleika

External


Since: Mar 08, 2007
Posts: 20



(Msg. 2) Posted: Thu Mar 08, 2007 3:04 pm
Post subject: Re: View SQL Query-String in Excel [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 8 Mar 2007 01:49:43 -0800, Dagmar
<Dagmar.DeleteThis@discussions.microsoft.com> wrote:

>Hi!
>
>We are using an application which creates Excel Pivot tables. These Pivot
>tables get their data from an SQL-Server. I need to see (maybe edit) the
>SQL-Query string. From your newsgroup I learned that the commands "?
>ActiveCell.QueryTable.CommandText" etc. would be the solution to my problem.
>
>However, when I run them in the immediate window I geht "Run-time error
>1004" Application-defined or object-defined error".
>

Dagmar: That will work for normal External Data Tables, but for
PivotTables based on external data, I think you'll need:

?ActiveSheet.PivotTables(1).PivotCache.CommandText

--
Dick Kusleika
http://www.dailydoseofexcel.com
Back to top
Login to vote
Dagmar

External


Since: Jun 13, 2006
Posts: 6



(Msg. 3) Posted: Thu Mar 08, 2007 11:36 pm
Post subject: Re: View SQL Query-String in Excel [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

That works! Thank you!

Dagmar

"Dick Kusleika" wrote:

> On Thu, 8 Mar 2007 01:49:43 -0800, Dagmar
> <Dagmar DeleteThis @discussions.microsoft.com> wrote:
>
> >Hi!
> >
> >We are using an application which creates Excel Pivot tables. These Pivot
> >tables get their data from an SQL-Server. I need to see (maybe edit) the
> >SQL-Query string. From your newsgroup I learned that the commands "?
> >ActiveCell.QueryTable.CommandText" etc. would be the solution to my problem.
> >
> >However, when I run them in the immediate window I geht "Run-time error
> >1004" Application-defined or object-defined error".
> >
>
> Dagmar: That will work for normal External Data Tables, but for
> PivotTables based on external data, I think you'll need:
>
> ?ActiveSheet.PivotTables(1).PivotCache.CommandText
>
> --
> Dick Kusleika
> http://www.dailydoseofexcel.com
>
Back to top
Login to vote
Dagmar

External


Since: Jun 13, 2006
Posts: 6



(Msg. 4) Posted: Wed Mar 14, 2007 8:55 am
Post subject: Re: View SQL Query-String in Excel [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi!

I have got another question:
Now, that I can read the SQL-Query I would like to change it.
e.g. the original query is like this:

SELECT Datum=L.Beginn, Mitarbeiter=M.Name,Klient=K.Suchbegrif + ' (' +
RTRIM(K.Kundennummer) + ')', Auftrag=A.Bezeichnung,
L.Stunden,
Expensargruppe=L.HGruppencode,
L.Periode,[Verkaufspreis]=L.Wert0,
Aliquotierung=Aliquot, Honorar=(isnull(L.Wert0,0)+Aliquot),
Bemerkung=L.Beschreibung,
Referat=M.Abteilungsnummer, Abteilung=M.DTA_Code,
Klientenkanzlei=K.Kanzleinummer
, Mitarbeiterkanzlei=M.Kanzleinummer, LC=L.Artikelnummer
FROM LeistLA0 L (NOLOCK)INNER JOIN Klientenstamm K (NOLOCK) ON
L.Kundennummer=K.Kundennummer
INNER JOIN Mitarbeiter M (NOLOCK) ON L.MAID=M.MAID
LEFT JOIN Auftrag A (NOLOCK) ON L.AuftragsID=A.AuftragsID
WHERE (L.Beginn Between '1.1.2006' And '31.12.2006')

It would be nice to change the L.Beginn Date in the end. However, I copied
the SQL-Query String above and added the
"?ActiveSheet.PivotTables(1).PivotCache.CommandText" in the front.
Unfortunately this does not work ("Syntax error ..."). I also tried less
complex SQL-Queries which do work.

Are there any better/more comfortable ways to change this query?

Thank you for your help!

Dagmar







Es funktioniert:



Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

ActiveSheet.PivotTables(1).PivotCache.CommandText = “select * from auftrag”

End Sub



"Dick Kusleika" wrote:

> On Thu, 8 Mar 2007 01:49:43 -0800, Dagmar
> <Dagmar RemoveThis @discussions.microsoft.com> wrote:
>
> >Hi!
> >
> >We are using an application which creates Excel Pivot tables. These Pivot
> >tables get their data from an SQL-Server. I need to see (maybe edit) the
> >SQL-Query string. From your newsgroup I learned that the commands "?
> >ActiveCell.QueryTable.CommandText" etc. would be the solution to my problem.
> >
> >However, when I run them in the immediate window I geht "Run-time error
> >1004" Application-defined or object-defined error".
> >
>
> Dagmar: That will work for normal External Data Tables, but for
> PivotTables based on external data, I think you'll need:
>
> ?ActiveSheet.PivotTables(1).PivotCache.CommandText
>
> --
> Dick Kusleika
> http://www.dailydoseofexcel.com
>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Query DAO All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET