Click here to Skip to main content
15,891,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I am working on asp.net with c# and I am new at this.

I want to create gridview to retrieve from sql server but I want to list equals cells as one.

For example;
We have data like below in sql
123 123 123
456 456 456
123 123 789
123 321 456
456 456 789
but I want to display
123 123
456 456
123 321
just this columns I have interested to list.

Is there any possibility to make this codes?

What I have tried:

I tried to google to find some example but there is no one made it something like I want.
Posted
Updated 7-May-21 6:05am

Probably something like:
SQL
SELECT col1, col2 from table WHERE col1 = col2;
 
Share this answer
 
Solution 1 will give you the results
>col1	col2
123		123
456		456
123		123
456		456
I.e. it will not return the value set 123 321. Assuming you just have reversed values and are not wanting all combinations then you could do something like (assumes SQL 2016 or better)
SQL
select col1,col2
from @demo
where col1 = col2 
or  REVERSE(col1) = col2
or REVERSE(col2) = col1;
which returns
col1	col2
123		123
456		456
123		123
123		321
456		456
To get just the three rows you list as your expected results you will need to use the DISTINCT keyword.
It gets more complex if you want to include col3 as well, but the principle is the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900