Solved

Re Arranging SQL columns

Posted on 2004-04-21
6
526 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ class logger 6 105
maven import project error 7 130
maven plugin not showing after installation 3 74
MAC and PC - Cheap video editing tools 4 132
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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.

832 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