Solved

Re Arranging SQL columns

Posted on 2004-04-21
6
514 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
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:namasi_navaretnam
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:srinib
Comment Utility
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
Comment Utility
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
Comment Utility

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now