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

I have used row count transformation to get the row count as final column but the row count populates in all the columns.

e.g. My file should look like this

A B C RowCnt
x y z NULL
g h i NULL
k l m 3

The "3" in the "RowCnt" column says the total number of records.

I achieved this :(

A B C RowCnt
x y z 3
g h i 3
k l m 3

I am stuck with this. Please help me in achieving the first result.

Thanks in advance.
Posted

1 solution

You can do something like -
SQL
SELECT A,B,C
,CASE WHEN ROW_NUMBER() OVER(ORDER BY A,B,C)=(SELECT COUNT(*) FROM dbo.YourTable)
      THEN (SELECT COUNT(*) FROM dbo.YourTable)
      ELSE NULL END AS RowCnt
FROM dbo.YourTable


If this doesn't help, please share the sql you have tried so far to get the o/p as shown in the question.

Hope, it helps :)
 
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