Link to home
Start Free TrialLog in
Avatar of srinib
srinib

asked on

Re Arranging SQL columns

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
 
Avatar of namasi_navaretnam
namasi_navaretnam
Flag of United States of America image

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-
Avatar of srinib
srinib

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of namasi_navaretnam
namasi_navaretnam
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srinib

ASKER

Hi Navaretnam,

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

Thanks again
Srinib
Avatar of srinib

ASKER

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

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