Solved

SQL Resultset field order

Posted on 2001-06-08
9
164 Views
Last Modified: 2013-12-18
Here is my SQL:

Qry.SQL = "select A.ABAN8, A.ABMLNM, A.ALADD1, A.ALADD2, A.ALADD3, A.ALADD4, A.ALCTY1, A.ALADDS, A.ALADDZ, C.A5CLMG, B.MAAN8, C.ABALPH, D.ABALPH, D.CAANAME from EDWDATA1.F01901 A, EDWDATA1.F0150 B, EDWDATA1.F01901 C, EDWARDQRY.F550101B D where (A.ABAT1 = 'IP' or A.ABAT1 = 'C') and A.ABAN8 = B.MAPA8 and B.MAOSTP = 'PAY' and B.MAAN8 = C.ABAN8 and C.A5CLMG = D.BROKER order by B.MAAN8, A.ABAN8"

To access the result set values I use:

doc.CustomerNumber = Res.GetValue(1)
doc.BrokerNumber = Res.GetValue(2)
ETC, ETC
doc.PersonName = Res.GetValue(14)


My question is I want to add a new field but I don't want to have to realign all the code.  I want to add a 15th value.  It's confusing to know which order each field will be in especially since there are three files I'm reading from.  I want my new field A.xyzfield to show up as the last value or Res.GetValue(15).  How should I structure the HTML?

-Snocross
0
Comment
Question by:snocross
  • 5
  • 4
9 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6167900
I am not very sure what you want, but to add another column to be extracted from table add the column name as shown

select A.ABAN8, A.ABMLNM, A.ALADD1, A.ALADD2, A.ALADD3, A.ALADD4, A.ALCTY1, A.ALADDS, A.ALADDZ,
C.A5CLMG, B.MAAN8, C.ABALPH, D.ABALPH, D.CAANAME , A.xyzfield

Orderby governs the ordering

GetValue gives the column value, not the row value. So ordering should not be a problem in your case.

~Hemanth
0
 
LVL 5

Author Comment

by:snocross
ID: 6167903
Maybe I need to clarify my question just in case...

If my SQL is simple like this:

Qry.SQL = "select A.ABAN8, A.ABMLNM, A.ALADD1 from EDWDATA1.F01901 A"

I'm assuming Res.GetValue(1) will be ABAN8 and Res.GetValue(2) will be ABMLNM and Res.GetValue(3) will be ALADD1.  Now if I move the fields around in the SQL will they get returned in that new order?  I'm just trying to figure out how the result set fields are ordered.  Are they basicly ordered in the order that I type them in the SQL?
0
 
LVL 5

Author Comment

by:snocross
ID: 6167913
Heman, if you do not use OrderBy then what order does it put the columns?  The order that I typed them regardless of the order on the source files?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 50 total points
ID: 6168227
There is a confusion here ?@!

Orderby affects the resultset, not the way you retrieved the columns.

eg:
Select col1, col2, col4, col3 from x orderby col2

will order the result by col2 (default ascending) but the order in which columns are retrieved would be the way you specify.

Got it!



0
 
LVL 5

Author Comment

by:snocross
ID: 6177763
So your example would display like this??

col2 (sorted), col1, col4, col3

I've done some testing now and if I don't use an OrderBy statement it seems to list them in the exact order that I write them in the sql.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6178186
no not like that

If your table is like this

col1 col2 col3 col4
x     3    xx    a
y     2    yy    b
z     1    zz    c

The the query will return the result as

z    1    zz    c
y    2    yy    b
x    3    xx    a

See the difference.

~Hemanth
0
 
LVL 5

Author Comment

by:snocross
ID: 6178547
Ok, but I don't care about the sorting, I am worried about the arrangement of the columns.  Anyway, the points are yours but my conclusion is that it arranges them in the order that I list them in my SQL.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 6178631
yes
0
 
LVL 5

Author Comment

by:snocross
ID: 6178654
Yes?  I didn't ask a yes/no question...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question