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

Edit SQL-Query String in Excel

 
   Home -> Office -> Query DAO RSS
Next:  Filtering by levels in a PivotTable  
Author Message
Dagmar

External


Since: Jun 13, 2006
Posts: 6



(Msg. 1) Posted: Fri Mar 16, 2007 1:51 am
Post subject: Edit SQL-Query String in Excel
Archived from groups: microsoft>public>excel>querydao (more info?)

Hi,

this is a follow up of the original question "View SQL Query-String in
Excel" which I postet here.

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
Back to top
Login to vote
Dick Kusleika

External


Since: Mar 08, 2007
Posts: 20



(Msg. 2) Posted: Tue Mar 20, 2007 5:11 pm
Post subject: Re: Edit SQL-Query String in Excel [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 16 Mar 2007 01:51:08 -0700, Dagmar
<Dagmar.RemoveThis@discussions.microsoft.com> wrote:

>
>Now, that I can read the SQL-Query I would like to change it.
>e.g. the original query is like this:
<snip>

>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?
>

Nope. There are no good ways. There's an extra space, or maybe not enough
spaces, or something else that's really hard to find. It would be nice if
there was an easier way.

Maybe this way is a *little* easier. I tend to use the Replace method, e.g.

ActiveSheet.PivotTables(1).PivotCache.CommandText =
Replace(ActiveSheet.PivotTables(1).PivotCache.CommandText, "WHERE (L.Beginn
Between '1.1.2006' And '31.12.2006')", "WHERE (L.Beginn Between '1.1.2007'
And '31.12.2007')")

You still have to get the ReplaceWith syntax right, but it takes the rest of
the SQL statement out of the picture. Make sure you include enough text in
the ReplaceWhat argument so that you don't inadvertantly replace more than
you bargained for.

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

External


Since: Jun 13, 2006
Posts: 6



(Msg. 3) Posted: Wed Mar 21, 2007 1:12 am
Post subject: Re: Edit SQL-Query String in Excel [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

thank you for your answer.

In which event should I place the SQL Query? Does it make any difference?
--> In the Excel MS Visual Basic Window, I select "Worksheet" and then
"PivotTableUpdate", "Change", "Calculate" etc....

Dagmar



"Dick Kusleika" wrote:

> On Fri, 16 Mar 2007 01:51:08 -0700, Dagmar
> <Dagmar.DeleteThis@discussions.microsoft.com> wrote:
>
> >
> >Now, that I can read the SQL-Query I would like to change it.
> >e.g. the original query is like this:
> <snip>
>
> >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?
> >
>
> Nope. There are no good ways. There's an extra space, or maybe not enough
> spaces, or something else that's really hard to find. It would be nice if
> there was an easier way.
>
> Maybe this way is a *little* easier. I tend to use the Replace method, e.g.
>
> ActiveSheet.PivotTables(1).PivotCache.CommandText =
> Replace(ActiveSheet.PivotTables(1).PivotCache.CommandText, "WHERE (L.Beginn
> Between '1.1.2006' And '31.12.2006')", "WHERE (L.Beginn Between '1.1.2007'
> And '31.12.2007')")
>
> You still have to get the ReplaceWith syntax right, but it takes the rest of
> the SQL statement out of the picture. Make sure you include enough text in
> the ReplaceWhat argument so that you don't inadvertantly replace more than
> you bargained for.
>
> --
> Dick Kusleika
> Microsoft MVP-Excel
> http://www.dailydoseofexcel.com
>
Back to top
Login to vote
Dick Kusleika

External


Since: Mar 08, 2007
Posts: 20



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

On Wed, 21 Mar 2007 01:12:08 -0700, Dagmar
<Dagmar.RemoveThis@discussions.microsoft.com> wrote:

>
>In which event should I place the SQL Query? Does it make any difference?
>--> In the Excel MS Visual Basic Window, I select "Worksheet" and then
>"PivotTableUpdate", "Change", "Calculate" etc....

When do you want it run? Are you prompting for new dates? Is the user
putting new dates in a cell?

Another option that I failed to mention is Parameters. You can read about
Parameters here

http://www.dicks-clicks.com/excel/ExternalData6.htm#Parameters

I don't think I've ever tried Parameters with a an externa data pivot table,
but I don't know why they wouldn't work.
--
Dick Kusleika
Microsoft MVP-Excel
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