cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kokitabayashi
Advocate I
Advocate I

Results from SQL query using subquery is blank

I'm currently running SQL command using Excel ODBC Driver and trying to run layers of JOIN statements using subquery but facing an issue.

 

I ran the same SQL query on My SQL DB via MySQL Workbench and that one worked as expected but, the same query with the same data running on PAD with Excel ODBC Driver gives me different (and unexpected) results.

 

What I'm trying to do overall: Join two tables trying multiple columns one by one using subqueries.

 

High level steps (my question is a subset of the step 1 and 2):

1. Join TBL_1 and TBL_2 with column 'A' => Keep the matched result (will call Res_X here) and unmatched result (will call Res_D here)

2. Join TBL_1 and Res_D (unmatched result from step 1) with column 'B' => Keep the matched result (will call Res_Z here) and unmatched result

3. Union ALL Res_X (matched result from step 1) and Res_Z (matched result from step 2)

4. Do the same operation using column 'C' and Union All the matched results (continue total four times)

 

Following is the test tables I'm using:

[TBL_1]

COL_ACOL_B
1001
1012
1023
1035
1046
1057
1068

 

[TBL_2]

COL_CCOL_D
100A
101B
102C
5D
601E
701F
10ABXXX801YYY
11ABCXXX801YYY

 

[Expected result (run query with unmatched result which is a subset of what I'm trying)]

c.COL_Ac.COL_BCOL_CCOL_Dd.COL_Ad.COL_A
  5D1035
  601E  
  701F  
  10ABXXX801YYY  
  11ABCXXX801YYY  

 

[Connection String]

kokitabayashi_0-1660276656733.png

As some columns have mixed data, I put "IMEX=1" in the connection string.

 

[SQL Query]

kokitabayashi_1-1660276722622.png

As some columns have mixed data, ON c.[COL_C] = d.[COL_B] returned an error. Because of it, I used LIKE without any wildcard to join two tables.

 

[Result from the SQL Query]

kokitabayashi_2-1660276851098.png

As you can see, the first JOIN statement is working and returning 5 rows but the second JOIN statement which is connecting the results from the 1st JOIN and the original table 1 is returning blank.

When I run this on MySQL via MySQL Workbench, it returns value for d.COL_A and d.COL_B as expected (103 and 5).

 

 

Following are some experiments I also did to specify where the issue is coming from.

 

If I run the subquery separately, the result looks like this (looks fine).

[Sub query only]

kokitabayashi_3-1660277414494.png

[Result when running sub query only]

kokitabayashi_4-1660277454576.png

 

If I just join the two tables using the soma column without using subquery, the result looks like this (looks fine).

[Query which is just joining two tables]

kokitabayashi_12-1660279262288.png

 

[Result from running the query which just join two tables]

kokitabayashi_6-1660277705503.png

 

If I flip the order of the original query it gave me different result (which is also confusing)

[Flip the order]

kokitabayashi_10-1660279037328.png

 

[Result from flipped SQL]

kokitabayashi_11-1660279094026.png

 

 

Based on the original result, result from MySQL and additional experiments, I'm assuming the issue is coming from how the subquery works on PAD & Excel ODBC combination.

 

Would be great if anyone could provide me an insight on this!

Thanks!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
ZS440
Resolver III
Resolver III

Hi.

@kokitabayashi 

Sorry I can't help you, but I have verified this.

In my environment, your Query works fine.

If there is any difference from my environment, you may have a clue.

 

Windows 10 Pro 21H2

Microsoft Excel for Microsoft 365 MSO (Version2207 Build 16.0.15427.20182) 64 bit 

Power Automate for desktop Version 2.22.263.222.02 Installer Edition

CleanShot 2022-08-13 at 12.09.16@2x.pngCleanShot 2022-08-13 at 12.10.46@2x.png

 

 

CleanShot 2022-08-13 at 12.13.32@2x.png

CleanShot 2022-08-13 at 12.15.15@2x.png

Underscores in column names are omitted, but it works fine.

CleanShot 2022-08-13 at 12.58.37@2x.png

In my opinion, it is better not to use underscores(_) in column names.

Because when using the Microsoft Office Access Database Engine OLE DB Provider, underscores act as ANSI SQL wildcards.

 

https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/compariso...

 

I can use "=" instead of "LIKE" if I do not use IMEX=1 for Extend Properties and the Excel data source is explicitly formatted as text type.

 

I hope it works out for you.

View solution in original post

ZS440
Resolver III
Resolver III

Hi @kokitabayashi 

Thank you for sharing your various verifications and results with us.
Thank you too.

 

However, I believe we need to be careful about IMEX=1.
IMEX=1 is telling the driver to read the data as text, but we are having problems.
I think we can confirm this by trying the following mixed data.

CleanShot 2022-08-14 at 13.45.04@2x.png

CleanShot 2022-08-14 at 13.52.43@2x.png


If there are more than 8 numerical values in a row and then text values are mixed, reading will fail and result in null, even though IMEX=1.

 

CleanShot 2022-08-14 at 13.51.38@2x.png
Therefore, I think it would be safe to pre-cleanse the data source side (EXCEL in this case) to text type data.

CleanShot 2022-08-14 at 13.58.00@2x.png

No use the IMEX=1 option.

CleanShot 2022-08-14 at 13.59.25@2x.png

Similarly, by data formatting all columns to text type, your query can be executed using "=" without the IMEX option.

CleanShot 2022-08-14 at 14.16.13@2x.pngCleanShot 2022-08-14 at 14.16.20@2x.png

CleanShot 2022-08-14 at 14.20.31@2x.png

CleanShot 2022-08-14 at 14.21.32@2x.png

If you do not want EXCEL to format your data, you can also explicitly enable IMEX=1 by setting HDR=NO. This will cause the first row of data to be the original column name and the entire column to be text type as well. (If the column name is a text type)

 

CleanShot 2022-08-14 at 14.47.57@2x.png

I hope this helps you or anyone else.

 

 

View solution in original post

5 REPLIES 5
ZS440
Resolver III
Resolver III

Hi.

@kokitabayashi 

Sorry I can't help you, but I have verified this.

In my environment, your Query works fine.

If there is any difference from my environment, you may have a clue.

 

Windows 10 Pro 21H2

Microsoft Excel for Microsoft 365 MSO (Version2207 Build 16.0.15427.20182) 64 bit 

Power Automate for desktop Version 2.22.263.222.02 Installer Edition

CleanShot 2022-08-13 at 12.09.16@2x.pngCleanShot 2022-08-13 at 12.10.46@2x.png

 

 

CleanShot 2022-08-13 at 12.13.32@2x.png

CleanShot 2022-08-13 at 12.15.15@2x.png

Underscores in column names are omitted, but it works fine.

CleanShot 2022-08-13 at 12.58.37@2x.png

In my opinion, it is better not to use underscores(_) in column names.

Because when using the Microsoft Office Access Database Engine OLE DB Provider, underscores act as ANSI SQL wildcards.

 

https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/compariso...

 

I can use "=" instead of "LIKE" if I do not use IMEX=1 for Extend Properties and the Excel data source is explicitly formatted as text type.

 

I hope it works out for you.

kokitabayashi
Advocate I
Advocate I

Thank you so much for your reply, @ZS440 

This is indeed, really helpful!

 

The following was the environment I was using when I originally posted.

 

** Original Test (Test-A) **

[Test Environment-A]

Windows 10 Enterprise 20H2

Microsoft Excel for Microsoft 365 MSO (Version 2108 Build 16.0.14326.21052) 64-bit

PAD Version 2.16.215.22020

 

[SQL & Connector]

(Refer to the original post)

 

[Result in the Test Environment-A (as posted in the original post)]

kokitabayashi_0-1660436436694.png

 

Based on your reply, I did the following additional experiments and got interesting results.

 

** Additional Test (Test-B) **

[Test Environment-B]

Windows 10 Pro 21H2

Microsoft Excel for Microsoft 365 MSO (Version 2207 Build 16.0.15427.20182) 64-bit

PAD Version 2.22.263.22202

 

[SQL & Connector]

(Same with the original one: Refer to the original post)

 

[Result in the Test Environment-B]

kokitabayashi_1-1660436825432.png

 

** Additional Test (Test-C) **

[Test Environment-C]

Windows 10 Pro 21H2
Microsoft Excel for Microsoft 365 MSO (Version 2207 Build 16.0.15427.20182) 64-bit
PAD Version 2.21.244.22174

 

[SQL & Connector]

(Same with the original one: Refer to the original post)

 

[Result in the Test Environment-C]

kokitabayashi_2-1660437016254.png

 

As you can see, in the two additional environments (Test-B and C), I got the same results as yours (which was what I was originally expecting).

For these additional tests, I created a new bot and new excel file from scratch in the original environment (Test-A) as well, just in case, but the result was the same ("d.COL_A" and "d.COL_B" are blank).

 

It seems like not only PAD version is different but also Windows 10 Pro version and Excel versions are also different; therefore, I cannot conclude which exactly software version difference is causing the issue, but at this moment, considering the maturity of the software and the number of users of it, I'm guessing it may be a bug in PAD version 2.16.215.22020.

 

 

Also, thank you for sharing your opinion on using the underscore in column names and also sharing the results of trying = without IMEX=1 instead of LIKE with IMEX=1.

 

I didn't know about what you mentioned about the underscore with ODBC and it sounds like I should stop using it whenever I have an option. It is great to know that.

 

 

For the use of = instead of LIKE without IMEX=1, I tried as the following but, it seemed like some data were dropped.

 

** Experiment of = without IMEX=1 **

[Connector]

kokitabayashi_3-1660438601575.png

[SQL replaced LIKE with =]

kokitabayashi_4-1660438644443.png

 

[Result (from Environment-A)]

kokitabayashi_5-1660438674722.png

 

[Result (from Environment-B)]

kokitabayashi_6-1660438819519.png

 

As you can see, in the both environments, some data from COL_C were dropped. As I still need these data in the later steps, I tried to figure out the solution and came up with using LIKE with IMEX=1, but if you see any risk doing this way (or any other better way to do it), it would be great if I could hear it!

 

Thank you!

 

ZS440
Resolver III
Resolver III

Hi @kokitabayashi 

Thank you for sharing your various verifications and results with us.
Thank you too.

 

However, I believe we need to be careful about IMEX=1.
IMEX=1 is telling the driver to read the data as text, but we are having problems.
I think we can confirm this by trying the following mixed data.

CleanShot 2022-08-14 at 13.45.04@2x.png

CleanShot 2022-08-14 at 13.52.43@2x.png


If there are more than 8 numerical values in a row and then text values are mixed, reading will fail and result in null, even though IMEX=1.

 

CleanShot 2022-08-14 at 13.51.38@2x.png
Therefore, I think it would be safe to pre-cleanse the data source side (EXCEL in this case) to text type data.

CleanShot 2022-08-14 at 13.58.00@2x.png

No use the IMEX=1 option.

CleanShot 2022-08-14 at 13.59.25@2x.png

Similarly, by data formatting all columns to text type, your query can be executed using "=" without the IMEX option.

CleanShot 2022-08-14 at 14.16.13@2x.pngCleanShot 2022-08-14 at 14.16.20@2x.png

CleanShot 2022-08-14 at 14.20.31@2x.png

CleanShot 2022-08-14 at 14.21.32@2x.png

If you do not want EXCEL to format your data, you can also explicitly enable IMEX=1 by setting HDR=NO. This will cause the first row of data to be the original column name and the entire column to be text type as well. (If the column name is a text type)

 

CleanShot 2022-08-14 at 14.47.57@2x.png

I hope this helps you or anyone else.

 

 

Hi @ZS440 ,

Thank you for sharing your insights and pointing out the potential risk relying on IMEX=1!

 

I tried what you explained about IMEX=1 on my end and was able to recreate the issue ("1hundred8" and "ten" disappear), as well. This is actually, an interesting and also a big problem.

 

Also, the solution you suggested (convert the columns to Text format, stop using IMEX=1, and Join on '=') worked great, as well.

I added a "Run VBScript" action for changing the columns' format to Text before running the SQL statement and everything is working great right now.

 

'Opens the Excel file'
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("%ExcelFile%")
objExcel.Application.Visible = False

'Selects the sheet 1'
Set objSheet = objWorkbook.Sheets("%SheetName%")

'Change the number format of the row to Text'
for col=1 to 2
objSheet.columns(col).NumberFormat = "@"
next

'Selects the sheet 2'
Set objSheet = objWorkbook.Sheets("%SheetName2%")

'Change the number format of the row to Text'
for col=1 to 2
objSheet.columns(col).NumberFormat = "@"
next

'Saves and closes the Excel file'
objWorkbook.Save
objWorkbook.Close SaveChanges = True
objExcel.Application.Quit
Set objExcel = Nothing

 

Thanks!

ZS440
Resolver III
Resolver III

Hi. @kokitabayashi 

I'm glad it worked out for you.

I have learned a lot from you as well.
Thanks for sharing your great idea of using VBScript to change the formatting.

Helpful resources

Announcements

Update! June 13th, Community Ambassador Call for User Group Leaders and Super Users

Calling all Super Users & User Group Leaders   UPDATE:  We just wrapped up June's Community Ambassador monthly calls for Super Users and User Group Leaders. We had a fantastic call with lots of engagement. We are excited to share some highlights with you!    Big THANK YOU to our special guest Thomas Verhasselt, from the Copilot Studio Product Team for sharing how to use Power Platform Templates to achieve next generation growth.     A few key takeaways: Copilot Studio Cookbook Challenge:  Week 1 results are posted, Keep up the great work!Summer of Solutions:  Starting on Monday, June 17th. Just by providing solutions in the community, you can be entered to win tickets to Power Platform Community Conference.Super User Season 2: Coming SoonAll communities moving to the new platform end of July We also honored two different community members during the call, Mohamed Amine Mahmoudi and Markus Franz! We are thankful for both leaders' contributions and engagement with their respective communities. 🎉   Be sure to mark your calendars and register for the meeting on July 11th and stay up to date on all of the changes that are coming. Check out the Super User Forum boards for details.   We're excited to connect with you and continue building a stronger community together.   See you at the call!

Copilot Cookbook Challenge | Week 2 Results | Win Tickets to the Power Platform Conference

We are excited to announce the "The Copilot Cookbook Community Challenge is a great way to showcase your creativity and connect with others. Plus, you could win tickets to the Power Platform Community Conference in Las Vegas in September 2024 as an amazing bonus.   Two ways to enter: 1. Copilot Studio Cookbook Gallery:  https://aka.ms/CS_Copilot_Cookbook_Challenge 2. Power Apps Copilot Cookbook Gallery: https://aka.ms/PA_Copilot_Cookbook_Challenge   There will be 5 chances to qualify for the final drawing: Early Bird Entries: March 1 - June 2Week 1: June 3 - June 9Week 2: June 10 - June 16Week 3: June 17 - June 23Week 4: June 24 - June 30     At the end of each week, we will draw 5 random names from every user who has posted a qualifying Copilot Studio template, sample or demo in the Copilot Studio Cookbook or a qualifying Power Apps Copilot sample or demo in the Power Apps Copilot Cookbook. Users who are not drawn in a given week will be added to the pool for the next week. Users can qualify more than once, but no more than once per week. Four winners will be drawn at random from the total qualifying entrants. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once. If they are drawn multiple times, another user will be drawn at random. Prizes:  One Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value, does not include travel, lodging, or any other expenses) Winners are also eligible to do a 10-minute presentation of their demo or solution in a community solutions showcase at the event. To qualify for the drawing, templates, samples or demos must be related to Copilot Studio or a Copilot feature of Power Apps, Power Automate, or Power Pages, and must demonstrate or solve a complete unique and useful business or technical problem. Power Automate and Power Pagers posts should be added to the Power Apps Cookbook. Final determination of qualifying entries is at the sole discretion of Microsoft. Weekly updates and the Final random winners will be posted in the News & Announcements section in the communities on July 29th, 2024. Did you submit entries early?  Early Bird Entries March 1 - June 2:  If you posted something in the "early bird" time frame complete this form: https://aka.ms/Copilot_Challenge_EarlyBirds if you would like to be entered in the challenge.   Week 1 Results:  Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1.  @Mathieu_Paris 1.   @SpongYe 2.  @Dhanush 2.   @Deenuji 3.  n/a3.   @Nived_Nambiar  4.  n/a4.   @ManishSolanki 5.  n/a5.    n/a   Week 2 Results:  Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. Kasun_Pathirana1. ManishSolanki2. cloudatica2. madlad3. n/a3. SpongYe4. n/a4. n/a5. n/a5. n/a

Win free tickets to the Power Platform Conference | Summer of Solutions

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**

Celebrating the June Super User of the Month: Markus Franz

Markus Franz is a phenomenal contributor to the Power Apps Community. Super Users like Markus inspire others through their example, encouragement, and active participation.    The Why: "I do this to help others achieve what they are trying to do. As a total beginner back then without IT background I know how overwhelming things can be, so I decided to jump in and help others. I also do this to keep progressing and learning myself." Thank you, Markus Franz, for your outstanding work! Keep inspiring others and making a difference in the community! 🎉  Keep up the fantastic work! 👏👏 Markus Franz | LinkedIn  Power Apps: mmbr1606  

Your Moment to Shine: 2024 PPCC’s Got Power Awards Show

For the third year, we invite you, our talented community members, to participate in the grand 2024 Power Platform Community Conference's Got Power Awards. This event is your opportunity to showcase solutions that make a significant business impact, highlight extensive use of Power Platform products, demonstrate good governance, or tell an inspirational story. Share your success stories, inspire your peers, and show off some hidden talents.  This is your time to shine and bring your creations into the spotlight!  Make your mark, inspire others and leave a lasting impression. Sign up today for a chance to showcase your solution and win the coveted 2024 PPCC’s Got Power Award. This year we have three categories for you to participate in: Technical Solution Demo, Storytelling, and Hidden Talent.      The Technical solution demo category showcases your applications, automated workflows, copilot agentic experiences, web pages, AI capabilities, dashboards, and/or more. We want to see your most impactful Power Platform solutions!  The Storytelling category is where you can share your inspiring story, and the Hidden Talent category is where your talents (such as singing, dancing, jump roping, etc.) can shine! Submission Details:  Fill out the submission form https://aka.ms/PPCCGotPowerSignup by July 12th with details and a 2–5-minute video showcasing your Solution impact. (Please let us know you're coming to PPCC, too!)After review by a panel of Microsoft judges, the top storytellers will be invited to present a virtual demo presentation to the judges during early August. You’ll be notified soon after if you have been selected as a finalist to share your story live at PPCC’s Got Power!  The live show will feature the solution demos and storytelling talents of the top contestants, winner announcements, and the opportunity to network with your community.  It's not just a showcase for technical talent and storytelling showmanship, show it's a golden opportunity to make connections and celebrate our Community together! Let's make this a memorable event! See you there!   Mark your calendars! Date and Time: Thursday, Sept 19th Location: PPCC24 at the MGM Grand, Las Vegas, NV 

Tuesday Tip | Accepting Solutions

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   To enhance our collaborative environment, it's important to acknowledge when your question has been answered satisfactorily. Here's a quick guide on how to accept a solution to your questions: Find the Helpful Reply: Navigate to the reply that has effectively answered your question.Accept as Solution: Look for the "Accept as Solution" button or link, usually located at the bottom of the reply.Confirm Your Selection: Clicking this button may prompt you for confirmation. Go ahead and confirm that this is indeed the solution.Acknowledgment: Once accepted, the reply will be highlighted, and the original post will be marked as "Solved". This helps other community members find the same solution quickly. By marking a reply as an accepted solution, you not only thank the person who helped you but also make it easier for others with similar questions to find answers. Let's continue to support each other by recognizing helpful contributions. 

Users online (4,536)