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

How will you optimize a stored procedure optimization?

525


What is wrong with sql server client libarary dll, ntwdblib.dll?

573


How to drop existing views from a database in ms sql server?

544


What types of replication are supported in sql server?

579


What is the difference between commit and rollback?

515






Explain what is cte (common table expression)?

638


how many bits ip address consist of? : Sql server database administration

474


What are sp_configure commands and set commands?

566


How do I install sql server?

476


Why is the need for data conversion transformations?

510


What do you understand by intent locks?

583


What is #table in sql server?

544


How can you append an identity column to a temporary table?

455


Difference between 2NF &3NF ?

686


How to insert and update data into a table with "insert" and "update" statements?

520