0

I have a group of data from excel file read the file and take the result in a variable for create a new excel with what are wrong and i try

local.sheetData =queryNew("FirstName,LastName,Address,Email,Phone,DOB,Role");
        for(row in data){
            queryAddRow(local.sheetData);
         
            if(row["First Name"] != '' || row["Last Name"] != '' || row["Address"] != '' || row["Email"] != '' || row["Phone"] != '' || row["DOB"] != '' || row["Role"] != ''){
                if(row["First Name"] === '' || row["Last Name"] === '' || row["Address"] === '' || row["Email"] === '' || row["Phone"] === '' || row["DOB"] === '' || row["Role"] === ''){

                    local.endresult = arrayToList(local.nullMessage)
                    querySetCell(local.sheetData, "FirstName", row["First Name"]);
                    querySetCell(local.sheetData, "LastName", row["Last Name"]);
                    querySetCell(local.sheetData, "Address", row["Address"]);
                    querySetCell(local.sheetData, "Email", row["Email"]);
                    querySetCell(local.sheetData, "Phone", row["Phone"]);
                    querySetCell(local.sheetData, "DOB", row["DOB"]);
                    querySetCell(local.sheetData, "Role", row["Role"]);
                   
                }else{
                    querySetCell(local.sheetData, "FirstName", row["First Name"]);
                    querySetCell(local.sheetData, "LastName", row["Last Name"]);
                    querySetCell(local.sheetData, "Address", row["Address"]);
                    querySetCell(local.sheetData, "Email", row["Email"]);
                    querySetCell(local.sheetData, "Phone", row["Phone"]);
                    querySetCell(local.sheetData, "DOB", row["DOB"]);
                    querySetCell(local.sheetData, "Role", row["Role"]);
                    
                }
            } 
        }
        
       return local.sheetData; 

it working fine and get the result like

enter image description here

i wand sort this query and show the any cell is empty that row show first. how to sort the query in coldfusion ?

8
  • 1
    Could it be that data already is a query object in your case? How does WriteDump(data) look like? Commented Mar 29, 2022 at 12:36
  • @Tomalak the image is result Commented Mar 30, 2022 at 3:33
  • That's what local.sheetData looks like. I asked what data looks like. Commented Mar 30, 2022 at 6:17
  • Oh sorry ,its show query resultset Commented Mar 30, 2022 at 6:36
  • 1
    It looks like the issue you are trying to solve is importing an excel sheet and its importing blank rows that have no data, check out github.com/cfsimplicity/spreadsheet-cfml can probably accomplish your task easier than your current solution Commented Mar 30, 2022 at 23:59

1 Answer 1

3

The easiest way to sort a query in ColdFusion is to use the Query-of-Queries feature.

tag syntax

<cfset myQuery = ...>
<cfquery name="sortedQuery" dbtype="query">
  SELECT * FROM myQuery ORDER BY col1, col2 DESC;
</cfquery>

cfscript syntax

var myQuery = ...;
var sortedQuery = queryExecute("
   SELECT * FROM myQuery ORDER BY col1, col2 DESC;
", {}, {dbtype: "query"});

In any case - if you insert rows in the right order, you don't need to sort anything, so pre-sorting data before your loop would be the most efficient option you have.

Sign up to request clarification or add additional context in comments.

2 Comments

my datas are coming from an excel file
@Shambu That does not matter. Once you have read the data into a Coldfusion query variable, you can use that variable in Query of Query logic (to create a sorted query like the answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.