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 |
|
sillylady
Starting Member
13 Posts |
Posted - 2007-05-24 : 01:24:10
|
| I have a query which is little complex. Now I want to pass a value to the query from another table. If the 1st query is for one particual year it's ok but the problem is when 1st query fetches data for a range of years. Query and the 2nd table has one common field that is Financial Year.The red color is the value from another table.SELECT INS.FinYr As [YEAR],((INSRev.FI_NetPremLessIns+INSRev.MA_NetPremLessIns+INSRev.MO_NetPremLessIns+INSRev.MI_NetPremLessIns)/ value from another table)*100 As [R16], FROM (InsuranceGen As INS LEFT JOIN INSURANCEGen As INS1 ON (INS1.FinYr=INS.FinYr-1 AND INS.Code=INS1.Code))LEFT JOIN INSRevGen as INSRev ON (INS.Code=INSRev.Code AND INS.FinYr=INSRev.FinYr)WHERE INS.Code='ABCD_INGN' AND INS.FinYr Between 2004 AND 2005---------------------------------------------------------------------Below is the tablel structure:Table1 (of which complex query is created)Code, FinYr, YrType and then Balancesheet and Incomestatement itemsTable2 (of which value must be passed to query)Finyr, GrossPremium, NetPremium,TotalAsset-------------------------------------------------------------Any help!!!Thanks |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-05-24 : 02:03:50
|
| Your post is not very clear currently. Your query does not make sense in it's current form. Please just post your table structure and desired results. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-24 : 02:10:13
|
don't forget some sample data KH |
 |
|
|
sillylady
Starting Member
13 Posts |
Posted - 2007-05-24 : 02:50:12
|
| The query you have seen in my 1st post which requires a value from another table for a particular year or range of years. So I need to pick the value of field 'GrPremium' from table 'InsGenInd' for a particular year or range of years and pass the value to my main query to divide. The problem I am facing is since my main query is already a complex one I don't want to make it more complex. Instead I want to pick 'GrPremium' from table 'InsGenInd' for a year or range of years provided by the users to the main query. Another problem can be that the main table 'InsuranceGen' may have data for a particular but the table 'InsGenInd' may not have data for that particular year. In that case 'GrPremium' will be zero.The InsuranceGen table structure is too long so I am just putting relevant fields here. The main query is created from this table.Code, FinYr, YrType and then Balancesheet and Incomestatement itemsTable InsGenInd:Finyr, GrossPremium, NetPremium,TotalAssetBoth table has one common field that is FinYr (financial year).Hope this time it is clear.Thanks |
 |
|
|
|
|
|
|
|