Hi I have two tables table one have County Info
and other one have the RowData
The Country table looks like
Country_ID Region_ID Country_Name Abbreviation Priority
----------- ----------- ------------------------- ------------ -----------
1 1 United States USA 1
2 1 US USA 1
3 1 Canada CA 2
4 2 United Kingdom UK 1
5 2 Germany DE 1
6 2 France FR 1
7 2 Italy IT 1
8 2 Spain ES 1
9 2 The Netherlands NL 1
10 2 Poland PL 2
11 2 Russia RU 2
and RowData is like
Tr_ID Countrys
----------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
729541 Germany,United Kingdom
729553 Italy,Poland,Russia,Spain
729580 Austria,Finland,France,Germany,Ireland,Italy,Poland,Portugal,Romania,Russia,Slovakia,Spain,Sweden,Switzerland,The Netherlands,United Kingdom
729726 Italy,Spain,United Kingdom
729737 Austria,United Kingdom
I want to rearrange county’s in as per the priority given in county table
Priority 1 county should be occurs first reaming country next with comma repeated
Please help me on this
Thanks
SQL Fiddle
MS SQL Server 2008 Schema Setup:
Query 1:
Results: