Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, February 23, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Make values from rows into columns in datagrid control
SLX_Novice
Posts: 246
 
Make values from rows into columns in datagrid controlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Nov 11 12:30 PM
fiogf49gjkf0d

Hi all


SLX LAN v7.2.1


I have a datagrid whose data (CustomerID, ItemNumber, ReportYear, Eaches) is obtained from myTableA. The end user selects 2 years from to comboboxes (cmbYear1 and cmbYear2). I can make the datagrid show the data like this:


CustomerID---ItemNumber---ReportedYear---Eaches


ABC---123---2010---50


ABC---123---2011---25


ABC---456---2010---15


ABC---456---2011---75


 


How can I get it to do this:


CustomerID---ItemNumber---2010---2011


ABC---123---50---25


ABC---456---15---75


It will basically put the eaches for the 2 years as columns. We want to be able to see the eaches for the 2 years they choose side by side. Any idea how I can do this?


Below is the code I used to build the datagrid for the first example.


<p>Dim strSQL_Yearly
Dim col_Yearly
Dim i_Yearly

 


With Datagrid1


         strSQL_Yearly = "SELECT sysdba.myTableA.CustomerID, sysdba.myTableA.ItemNumber, sysdba.myTableA.REPORTEDYEAR , SUM(sysdba.myTableA.EACHES) AS Total_Eaches   FROM sysdba.myTableA WHERE (sysdba.myTableA.REPORTEDYEAR = '" & cmbYear1.Text & "') OR (sysdba.myTableA.REPORTEDYEAR = '" & cmbYear2.Text & "') GROUP BY sysdba.myTableA.CustomerID, sysdba.myTableA.ItemNumber, sysdba.myTableA.REPORTEDYEAR"


        .SQL.Text = strSQL_Yearly


        With .Columns


            If (.Count > 0) Then


                For i_Yearly = 0 To .Count - 1


                    .Item(0).Delete
                Next


            End If


             Set col_Yearly = .Add(0)
             col_Yearly.FieldName = "CustomerID"
             col_Yearly.Caption = "Customer Number"
             col_Yearly.Readonly = True
             col_Yearly.Width = 90
             col_Yearly.Alignment = 2
             col_Yearly.Alignment = 2
             col_Yearly.HeaderAlignment = 2


             Set col_Yearly = .Add(0)
             col_Yearly.FieldName = "ItemNumber"
             col_Yearly.Caption = "Item Number"
             col_Yearly.Readonly = True
             col_Yearly.Width = 90
             col_Yearly.Alignment = 2
             col_Yearly.HeaderAlignment = 2


             Set col_Yearly = .Add(0)
             col_Yearly.FieldName = "ReportedYear"
             col_Yearly.Caption = "Year"
             col_Yearly.Readonly = True
             col_Yearly.Width = 90
             col_Yearly.Alignment = 2
             col_Yearly.HeaderAlignment = 2


             Set col_Yearly = .Add(0)
             col_Yearly.FieldName = "Total_Eaches"
             col_Yearly.Caption = "Eaches"
             col_Yearly.Readonly = True
             col_Yearly.Width = 90
             col_Yearly.Alignment = 2
             col_Yearly.HeaderAlignment = 2


        End With


       .Refresh


    End With

[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: Make values from rows into columns in datagrid controlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Nov 11 1:10 PM
fiogf49gjkf0d

The first thing would be to get the Data on your SQL statement, try something like this:


 



SELECT 


  sysdba.myTableA.CustomerID


, sysdba.myTableA.ItemNumber


, SUM(CASE WHEN sysdba.myTableA.REPORTEDYEAR = '" & cmbYear1.Text & "' THEN


    sysdba.myTableA.EACHES


  ELSE


    0


  END) AS SUMYEAR1


, SUM(CASE WHEN sysdba.myTableA.REPORTEDYEAR = '" & cmbYear2.Text & "' THEN


    sysdba.myTableA.EACHES


  ELSE


    0


  END) AS SUMYEAR2


FROM sysdba.myTableA 


WHERE 


(sysdba.myTableA.REPORTEDYEAR = '" & cmbYear1.Text & "') OR (sysdba.myTableA.REPORTEDYEAR = '" & cmbYear2.Text & "') 


GROUP BY sysdba.myTableA.CustomerID, sysdba.myTableA.ItemNumber



(You may need to finalize the SQL Statement as I haven't tested it....)


 


Once you have the SQL statement, generate the Columns dynamically as you are now (off course based on the new Schema) and set the Caption of the Year Columns to be based on the Combo Boxes:


e.g.


 Set col_Yearly = .Add(0)
  col_Yearly.FieldName = "SUMYEAR1"
  col_Yearly.Caption = 
cmbYear1.Text
  col_Yearly.Readonly = True
  col_Yearly.Width = 90
  col_Yearly.Alignment = 2
  col_Yearly.HeaderAlignment = 2


 

[Reply][Quote]
SLX_Novice
Posts: 246
 
Re: Make values from rows into columns in datagrid controlYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Nov 11 1:20 PM
fiogf49gjkf0d

That was it! Thanks Raul!

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 2/23/2025 4:10:04 PM