Translate
Sunday, 17 November 2013
Wednesday, 13 November 2013
My Blog List
1. http://karuppusamyg.blogspot.in/2013/11/sort-order-on-column-with-multiple.html
2. How to merge more than 1 cell value with a comma in a single cell of a row in SQLServer.
http://karuppusamyg.blogspot.in/2013/11/how-to-merge-more-than-1-cell-value.html
2. How to merge more than 1 cell value with a comma in a single cell of a row in SQLServer.
http://karuppusamyg.blogspot.in/2013/11/how-to-merge-more-than-1-cell-value.html
Sort Order on column with multiple decimal places
SELECT *
FROM (
VALUES
('1'),
('3.3'),
('1.1'),
('4.5.6'),
('1.4.3.1.1'),
('11.2')
) v (version)
ORDER BY
CAST('/' + version + '/' AS hierarchyid)
;
Example: order by CAST('/' + ColumnName + '/' AS hierarchyid)
How to merge more than 1 cell value with a comma in a single cell of a row in SQLServer.
Create table #temp1
(
Name varchar(10)
)
Create table #temp2
(
Name varchar(10),
Location varchar(100)
)
Insert into #temp1
values ('h' ),('I' )
Insert into #temp2
values ('h','delhi'),
('h','Mumbai'),
('h','Hyderabad'),
('I','Chennai'),
('I','Delhi')
Select *from #temp1
Select *from #temp2
select t.Name,
STUFF(( SELECT ', ' +te.Location
FROM #temp2 te
WHERE T.Name = te.Name
FOR XML PATH ('')
),1,1,'') as Location --//Do You want to add another column just you have to use another stuff stmt.
from #temp1 t
group by t.Name
DROP TABLE #temp1;
DROP TABLE #temp2;
Subscribe to:
Posts (Atom)