Lazarus

Programming => Databases => Topic started by: Gizmo on April 21, 2021, 10:40:22 pm

Title: [SOLVED] Comparing cells of two columns and show mismtaches - SQLite
Post by: Gizmo on April 21, 2021, 10:40:22 pm
My program uses SQLite.

I have 4 columns in a DBGrid.

I want to compare Columns 2 and 4 and compare the strings in each, and where they don't match, I want to show the rows with the cells of all 4 columns.

I am using this, but it is showing me two columns, and more critically it is showing me all the values instead of just the few that do not match

Code: SQL  [Select][+][-]
  1. TSQLQuery(DBGrid.DataSource.Dataset).SQL.Text := 'SELECT ColumnText2, ColumnText4 FROM TBL_MAINTABLE WHERE ColumnText2 <> ColumnText4';    
  2.  

I'm fairly new to SQL overall so would value a pointer? Thanks
Title: Re: Comparing cells of two columns and show mismtaches - SQLite
Post by: dseligo on April 21, 2021, 11:53:07 pm
You should have all 4 columns in 'select' so they are in your result set:

Code: SQL  [Select][+][-]
  1. TSQLQuery(DBGrid.DataSource.Dataset).SQL.Text := 'SELECT ColumnText1, ColumnText2, ColumnText3, ColumnText4 FROM TBL_MAINTABLE WHERE ColumnText2 <> ColumnText4';    
  2.  

Quote
and more critically it is showing me all the values instead of just the few that do not match

Your 'where' condition looks OK for what you've described.
Are you saying that ColumnText2 and ColumnText4 contain exactly the same data and are shown?
Maybe I didn't understand you, so can you give some example data?
Title: Re: [SOLVED] Comparing cells of two columns and show mismtaches - SQLite
Post by: Gizmo on April 22, 2021, 12:23:50 am
Missing the wood for trees again! Thank you sir. That has resolved the issue!
Title: Re: [SOLVED] Comparing cells of two columns and show mismtaches - SQLite
Post by: dseligo on April 22, 2021, 09:43:38 am
You're welcome, I'm glad it is solved
TinyPortal © 2005-2018