Using dbquery (Optionally set fieldnames to 1)

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
terencepjf
Newbie
Posts: 15
Joined: Wed Dec 19, 2007 9:16 pm

Using dbquery (Optionally set fieldnames to 1)

Post by terencepjf » Sat Jan 10, 2009 5:24 pm

Hi; I tried using this switch (Ver 11) and not getting the desired results...

DBQuery>dbh,SQL,rsRecordset,numrecs,numfields,1
...
WriteLn>filename,result,rsRecordset_%r%_%f%

I get the following:
17;rsRecordset_1_2;rsRecordset_1_3;rsRecordset_1_4;rsRecordset_1_5...

This is really strange as I get the # 17 at the start and have no idea where this is coming from...

Any help would be appreciated

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jan 10, 2009 5:45 pm

Looks like you are asking it to return field names but then trying to output based on numbers:
WriteLn>filename,result,rsRecordset_%r%_%f%
What's f?

Step past the DBQuery line in the debugger and look in the watch list. You should see variables like:

rsRecordset_1_NAME

etc

Instead of a number at the end you'll see the field name.

Clearly you can't then output using a variable with a number since no such var exists.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

terencepjf
Newbie
Posts: 15
Joined: Wed Dec 19, 2007 9:16 pm

Post by terencepjf » Sat Jan 10, 2009 6:01 pm

Marcus; I'm trying to get the field names as in a header row as in...

[code]
SRT>PrintHeader
Let>r=0
Repeat>r
Let>r=r+1
Let>f=0
Repeat>f
Let>f=f+1
Length>rsRecordset_%r%_%f%,vlen
if>f=1
Let>WLN_NOCRLF=1
If>vlen=0
WriteLn>filename,NULL
ELSE
WriteLn>filename,result,rsRecordset_%r%_%f%
ENDIF
WriteLn>filename,result,;
ELSE
If>vlen=0
WriteLn>filename,NULL
ELSE
WriteLn>filename,result,rsRecordset_%r%_%f%
ENDIF
if>ffilename,result,;
ENDIF
ENDIF
Until>f=numfields
WriteLn>filename,result,CRLF
Until>r=1
Let>WLN_NOCRLF=0
END>PrintHeader
[/code]

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jan 10, 2009 6:14 pm

That makes no sense - your loop is referring to the fields numerically but you are asking it to return the names.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

terencepjf
Newbie
Posts: 15
Joined: Wed Dec 19, 2007 9:16 pm

Post by terencepjf » Sat Jan 10, 2009 6:22 pm

Marcus; I get the data all right, but I want to get the field names as a top row for reference.

Can you provide an example please?

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7393
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jan 10, 2009 6:32 pm

The idea is that you already know the field names and you use them to reference the array.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts