if we have a column (Key) in a table.
and values of that column is
Key
1
1
1
2
2
3
3
4
4
5
5
5
and we want to show the data after query..like..

1(3)
2(3)
3(2)
4(2)
5(3)
how many times a single term comes..

Answer Posted / praveen singh

create table #temp1(id int)

insert into #temp1 values(4)


declare @str nvarchar(500)
select @str=''
select @str =@str+ id from (select cast(id as varchar) +'('+
cast(count(id) as varchar(22))+ ')' id from #temp1 group
by id) t
select @str


output will be :1(5)2(1)3(2)4(1)

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a transaction? : Sql server database administration

673


What is the difference between a function and a trigger?

792


Which are the important points to note when multilanguage data is stored in a table?

707


What is set nocount on?

709


you added a row to a view, but the row is not shown on the view. Explain how this can happen, and how you can remedy the situation

732


Explain the microsoft sql server delete command? : SQL Server Architecture

792


What is the difference between Triggers and Stored Procedure?

787


What is faster join or union?

825


Explain about the command-line tool SQLCMD?

764


What is the use of attributehierarchyvisible ? : sql server analysis services, ssas

820


What is filter index?

722


How to create a simple stored procedure in ms sql server?

749


What are the extra roles available in msdb? : sql server security

876


Write a program to fetch first 10 records from a file?

784


Name and describe few console utilities for ssrs?

264