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
How will you optimize a stored procedure optimization?
What is wrong with sql server client libarary dll, ntwdblib.dll?
How to drop existing views from a database in ms sql server?
What types of replication are supported in sql server?
What is the difference between commit and rollback?
Explain what is cte (common table expression)?
how many bits ip address consist of? : Sql server database administration
What are sp_configure commands and set commands?
How do I install sql server?
Why is the need for data conversion transformations?
What do you understand by intent locks?
What is #table in sql server?
How can you append an identity column to a temporary table?
Difference between 2NF &3NF ?
How to insert and update data into a table with "insert" and "update" statements?