| Author |
Topic |
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-15 : 01:18:38
|
| Hi experts,I have two tables tbl_reqforproposal,tbl_countrytbl_reqforproposalRFP_Requestid ,RFP_Country ,RFP_Name 1 98 A2 3 B3 98 c4 98 D5 1 E6 1 F7 3 G8 3 H9 98 I tbl_countryCountry ,Country_name 1 United States2 PAK3 UK4 United Arab Emirates5 Austria98 INDIAplease find the expected output below,based on the availability of country i need to display the result, for example in tbl_reqforproposal, the ref_country india occurs four time so i want to display india first, then uk three times i want to display uk secound and then United States two times display i want to display lastPlease help this concernREF_Name ,Country_nameA INDIAC INDIAD INDIAI INDIAB UKG UKH UKE United StatesF United StatesThanks an Advance |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-07-15 : 01:24:44
|
| select rfp_name,country_name from tbl_reqforproposal r inner join tbl_country c on r.RFP_Country = c.Country order by country_name |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-15 : 01:34:19
|
I assumed you are using 2005/2008DECLARE @tbl_reqforproposal TABLE( RFP_Requestid int, RFP_Country int, RFP_Name CHAR)INSERT INTO @tbl_reqforproposalSELECT 1, 98, 'A' UNION ALLSELECT 2, 3, 'B' UNION ALLSELECT 3, 98, 'C' UNION ALLSELECT 4, 98, 'D' UNION ALLSELECT 5, 1, 'E' UNION ALLSELECT 6, 1, 'F' UNION ALLSELECT 7, 3, 'G' UNION ALLSELECT 8, 3, 'H' UNION ALLSELECT 9, 98, 'I'DECLARE @tbl_country TABLE( Country int, Country_name varchar(20))INSERT INTO @tbl_countrySELECT 1, 'United States' UNION ALLSELECT 2, 'PAK' UNION ALLSELECT 3, 'UK' UNION ALLSELECT 4, 'United Arab Emirates' UNION ALLSELECT 5, 'Austria' UNION ALLSELECT 98, 'INDIA'SELECT r.RFP_Name, c.Country_nameFROM @tbl_reqforproposal r INNER JOIN @tbl_country c ON r.RFP_Country = c.CountryORDER BY COUNT(*) OVER (PARTITION BY c.Country_name) DESC, r.RFP_Name KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
RajuY
Starting Member
1 Post |
Posted - 2009-07-15 : 02:53:34
|
quote: Originally posted by khtan I assumed you are using 2005/2008DECLARE @tbl_reqforproposal TABLE( RFP_Requestid int, RFP_Country int, RFP_Name CHAR)INSERT INTO @tbl_reqforproposalSELECT 1, 98, 'A' UNION ALLSELECT 2, 3, 'B' UNION ALLSELECT 3, 98, 'C' UNION ALLSELECT 4, 98, 'D' UNION ALLSELECT 5, 1, 'E' UNION ALLSELECT 6, 1, 'F' UNION ALLSELECT 7, 3, 'G' UNION ALLSELECT 8, 3, 'H' UNION ALLSELECT 9, 98, 'I'DECLARE @tbl_country TABLE( Country int, Country_name varchar(20))INSERT INTO @tbl_countrySELECT 1, 'United States' UNION ALLSELECT 2, 'PAK' UNION ALLSELECT 3, 'UK' UNION ALLSELECT 4, 'United Arab Emirates' UNION ALLSELECT 5, 'Austria' UNION ALLSELECT 98, 'INDIA'SELECT r.RFP_Name, c.Country_nameFROM @tbl_reqforproposal r INNER JOIN @tbl_country c ON r.RFP_Country = c.CountryORDER BY COUNT(*) OVER (PARTITION BY c.Country_name) DESC, r.RFP_Name KH[spoiler]Time is always against us[/spoiler]
OrSELECT r.RFP_Name, c.Country_nameFROM @tbl_reqforproposal r INNER JOIN @tbl_country c ON r.RFP_Country = c.CountryGROUP BY c.Country_name ,RFP_NameORDER BY c.Country_name,RFP_Name |
 |
|
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-07-15 : 03:34:11
|
Thanks for your reply. Actually what I need is, I have two tables tbl_reqforproposal,tbl_countryI want to list all the countries. It should display in the order, the more time inserted country (RFP_Country) in tbl_reqforproposal should come at top.tbl_reqforproposalRFP_Requestid ,RFP_Country ,RFP_Name 1 98 A2 3 B3 98 c4 98 D5 1 E6 1 F7 3 G8 3 H9 98 I tbl_countryCountry ,Country_name 1 United States2 PAK3 UK4 United Arab Emirates5 Austria98 INDIAplease find the expected output below,based on the availability of country i need to display the result, for example in tbl_reqforproposal, the ref_country india occurs four time so i want to display india at first position, then uk three times it should display uk at secound position and then United States two times then it should display US at third position and other countries sholud follow up like this.Please us help in this concernCountry_nameINDIAUKUnited StatesUnited Arab EmiratesAustriaPAKThanks in Advancequote: Originally posted by bklr select rfp_name,country_name from tbl_reqforproposal r inner join tbl_country c on r.RFP_Country = c.Country order by country_name
|
 |
|
|
|
|
|