Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2012-05-31 : 05:13:02
|
| Dear Expert,I have following table schemaFromCountry intFromCity intToCountry intToCity intAmount intI want to select data with the following parameters.FromCountry : XFromCity : All (all cities in that country X)ToCountry : YToCity : All (all cities in that country Y)So if i have 2 cities in country X and 3 cities in country Y i should get the 2*3 = 6 Records.Performance is my concern, could you help me write such query.Thanks! |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-05-31 : 05:37:23
|
| select t1.fromcity, t2.tocityfrom tbl t1cross join tbl t2where t1.fromcountrty = 'x'and t2.tocountrty = 'y'orselect t1.fromcity, t2.tocityfrom (select * from tbl where fromcountrty = 'x' and tocountrty = 'y') t1cross join (select * from tbl where fromcountrty = 'x' and tocountrty = 'y') t2==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2012-06-02 : 01:52:38
|
| Thanks nigelrivett for your kind reply! |
 |
|
|
|
|
|