Solved

Re Arranging SQL columns

Posted on 2004-04-21
6
533 Views
Last Modified: 2013-12-26
Hi,

I have a window with selection criteria dw and resultset dw. When user enters some values in selection criteria dw fields, then i am forming the where clause in retrieve button clicked event, and setting the same to the resultset dw and then retreiving the result set.
Now the user requirement is...  
Example :
1)
If he enters City and Birthdate fileds in selection criteria then, these columns should come first in the resultset and rest should follows . I.e   City   BirthDate   Name   Phone   State ....
2)
If he enters state and phone then the resultset should be  State  Phone  City  Birthdate Name Etc...

I have all these columns in the resultset, i need to rearrange these columns as per selection criteria fields.


Thanks in Advance
Srinib
 
0
Comment
Question by:srinib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10882194
Method 1)

Build the entire sql dynamically. Not just there where clause. This was you place the selected columns on top. Then use sytanfromsql, create functions to create the datawindow.

Method 2)
Use GetSQLSelect, SetSQLSelect functions. Use GetSQLSelect to obtain currect sql. Modify current sql so that selected columns are on the top.

Use Modify to set column headers etc.

If you make it a grid style dw then user can re-arrage themselves.

regards-
0
 
LVL 1

Author Comment

by:srinib
ID: 10889039
Hi,

I have all the selected fields in the array. Now i need to rearrange these fields in my original sql string.

Example:
I have to selected fileds in array i.e ls_array[1]= 'Address.City' and ls_array[2] = 'Address.State'

My original SQL is as follows...i have this in one string

Select address.name,address.lname,address.city,address.state,address.phone
where address.city = 'NewYork' and address.state = 'NY'

Now i need all the fileds which are there in array should come first and rest should come next.
Final SQL should be like this..
select address.city,address.state,address.name,address.lname,address.phone
where address.city = 'NewYork' and address.state = 'NY'

If i can get the above final sql then i can prepare the dynamic dw based on that.

So, please give me the logic for repositioning sql columns with the array columns.

Thanks
Srinib
0
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 75 total points
ID: 10889458
Psedo-code: If using PFC: Just an idea. Refine it further as needed.

string ls_sql, ls_cols
long ll_ub
n_cst_string       lnv_string

ls_sql = dw_1.GetSqlSelect()
ll_ub = upperbound(ls_array)
ls_cols = ' '
ls_sql = lnv_string.of_GlobalReplace(ls_sql, 'from' , ', from ')

for ll_i = 1 to ll_ub
   ls_sql = lnv_string.of_GlobalReplace(ls_sql, ls_array[ll_i] + ',' , ' ')
   ls_cols = ls_cols + ls_array[ll_i] + ', '
next

ls_cols = left(ls_cols, len(ls_cols) - 2)
ls_sql = lnv_string.of_GlobalReplace(ls_sql, 'select ' , 'select ' + ls_cols)

messagebox("debug", ls_sql)

Debug it. This is the basic idea. Modify as needed still you get the right sql.

regards-


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:srinib
ID: 10890450
Hi Navaretnam,

I am not using PFCs, can you please give me the user defined global function.

Thanks again
Srinib
0
 
LVL 1

Author Comment

by:srinib
ID: 10891262
Thanks Navaretnam.. I have written global function for replacing...
Your basic idea helped me a lot in this..

Still i have one doubt... why these line required?

ls_sql = lnv_string.of_GlobalReplace(ls_sql, 'from' , ', from ')
ls_cols = left(ls_cols, len(ls_cols) - 2)

Thanks again
Srinib
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 10911846

// This line is to add a comma beside all column names.
ls_sql = lnv_string.of_GlobalReplace(ls_sql, 'from' , ', from ')

// This line is to remove comma at the end.
ls_cols = left(ls_cols, len(ls_cols) - 2)

Let me know if this does not makes sense.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

730 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