Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Concatenate	                 concatenatecount	result
ABNS CONSTRUCTIONS BNREDDY NAGAR	        NULL	1
ABNS CONSTRUCTIONS BNREDDY NAGAR	        NULL	2
ABNS CONSTRUCTIONS BNREDDY NAGAR	        NULL	3
ACC LIMITED, MYSORE ROAD, BLR	            NULL	1
ACC LIMITED, MYSORE ROAD, BLR	            NULL	2
ASK ENTERPRISES	                            NULL	1
ASK ENTERPRISES	                            NULL	2
ASK ENTERPRISES	                            NULL	3
ASK ENTERPRISES	                            NULL	4


What I have tried:

Required output has been mentioned in result column , same need to be updated to concatenatecount column using sql query... pleas help me on the same
Posted
Updated 21-Apr-17 3:13am
Comments
CHill60 21-Apr-17 6:42am    
The "What I have tried" section is for the code that you have tried and are having problems with.
Why are 'ABNS CONSTRUCTIONS BNREDDY NAGAR', 'ACC LIMITED, MYSORE ROAD, BLR' and 'ASK ENTERPRISES' all having result = 1?
Your question is not at all clear
Tryingtobeageek 21-Apr-17 7:33am    
see duplicates are there in the column i need the partition ... to updated to concatenarecount column join concatenate column

1 solution

The thing you are looking for is "Window Functions" - there is an article here - Window Functions in SQL Server - Simple Talk[^]

I created your data in a table like this
SQL
create table demo
(
	id int identity(1,1),
	[Concatenate]	 nvarchar(125),
	concatenatecount int,
	result int
)
insert into demo values
('ABNS CONSTRUCTIONS BNREDDY NAGAR',	NULL,	1),
('ABNS CONSTRUCTIONS BNREDDY NAGAR',	NULL,	2),
('ABNS CONSTRUCTIONS BNREDDY NAGAR',	NULL,	3),
('ACC LIMITED, MYSORE ROAD, BLR',	NULL,	1),
('ACC LIMITED, MYSORE ROAD, BLR',	NULL,	2),
('ASK ENTERPRISES',	                NULL,	1),
('ASK ENTERPRISES',	                NULL,	2),
('ASK ENTERPRISES',	                NULL,	3),
('ASK ENTERPRISES',	                NULL,	4)

With Window Functions you can specify how you want the data grouped using the OVER clause - in other words there is no need for a GROUP BY... Like this:
SQL
select id, [Concatenate], result,
		COUNT(*) OVER (PARTITION BY [Concatenate]), 
		ROW_NUMBER() OVER (PARTITION BY [Concatenate] ORDER BY [Concatenate])
from demo
And that gave me the output:
1	ABNS CONSTRUCTIONS BNREDDY NAGAR	1	3	1
2	ABNS CONSTRUCTIONS BNREDDY NAGAR	2	3	2
3	ABNS CONSTRUCTIONS BNREDDY NAGAR	3	3	3
4	ACC LIMITED, MYSORE ROAD, BLR		1	2	1
5	ACC LIMITED, MYSORE ROAD, BLR		2	2	2
6	ASK ENTERPRISES				1	4	1
7	ASK ENTERPRISES				2	4	2
8	ASK ENTERPRISES				3	4	3
9	ASK ENTERPRISES				4	4	4
I included "result" just to check the expected results - it's the last two columns that contain the information you need
 
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