How to return blank cells for duplicate values and keep only cells that are different?
I have a query that selects some fields to display from a table
SELECT Field1, Field2, Field3, Field4 FROM table1
I want instead of returning:
alt text http://img186.imageshack.us/img186/3455/87921605.png
To return:
alt text http://img227.imageshack.us/img227/3921/85722509.png
How can I modify my SQL statement to return the second digit? Or at least how do I change the properties of gridview.Net to do this (if possible)?
+2
a source to share
1 answer
You can do this with a regular table expression ( WITH
), self-join functions, and ROW_NUMBER
and NULLIF
.
WITH t AS (SELECT *, ROW_NUMBER() OVER (ORDER BY Field1) rownum FROM table1)
SELECT NULLIF(curr.Field1, prev.Field1) Field1,
NULLIF(curr.Field2, prev.Field2) Field2,
NULLIF(curr.Field3, prev.Field3) Field3
FROM t curr
LEFT OUTER JOIN t prev ON prev.rownum = curr.rownum - 1
+3
a source to share