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

‘Order by’ is not allowed in a view how can you sort information from a view?

582


Difference between connected and disconnected database in .net with sql server?

577


What are the different types of collation sensitivity?

551


How to find index size for each index on table?

583


What is blocking and how would you troubleshoot it? : sql server database administration

589






How are the exceptions handled in sql server programming?

607


What are different types of statement?

523


What is sql view?

542


How do you create an execution plan?

492


Describe triggers features and limitations?

504


Explain what are the events recorded in a transaction log?

552


How to change parameter value inside the report?

104


What are statistics?

566


Why use identity in sql server?

560


How to insert multiple rows with one insert statement in ms sql server?

582