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
what is a transaction? : Sql server database administration
What is the difference between a function and a trigger?
Which are the important points to note when multilanguage data is stored in a table?
What is set nocount on?
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
Explain the microsoft sql server delete command? : SQL Server Architecture
What is the difference between Triggers and Stored Procedure?
What is faster join or union?
Explain about the command-line tool SQLCMD?
What is the use of attributehierarchyvisible ? : sql server analysis services, ssas
What is filter index?
How to create a simple stored procedure in ms sql server?
What are the extra roles available in msdb? : sql server security
Write a program to fetch first 10 records from a file?
Name and describe few console utilities for ssrs?