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 |
|
shubhada
Posting Yak Master
117 Posts |
Posted - 2009-03-19 : 05:55:41
|
| i have following tabletable1LID LType LLoss LNAV1 L_Type1 100 8002 L_Type2 900 890MID MType MLoss MNAV1 M_Type1 200 8002 M_Type2 1000 790I am getting I/P as type may be LType or MType and depending on the Type, I want to select (LLoss, LNAV ) or (MLoss, MNAV) for ex - if Type = L_Type1 then my query will return L_Type1 100 800 if Type = M_Type2 then my query will return M_Type2 1000 790I have to handle this in view.How I can do this?SQLTeam |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-03-19 : 06:05:04
|
| I can't get your Table Structure? will u explain?RegardsSenthil.C----------------------------------------------------------------------------Server: Msg 3902, Level 16, State 1, Line 1The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. |
 |
|
|
shubhada
Posting Yak Master
117 Posts |
Posted - 2009-03-19 : 06:50:42
|
| Table structure as followPrimaryTableLoanID LID MID SelectedType---------- -------- ---------- -------------1 1 1 NULL2 2 2 LType13 3 3 MType2table1LID LType LLoss LNAV----- ----- -------- ----------1 L_Type1 100 8002 L_Type2 900 890table2MID MType MLoss MNAV----- ------- -------- ----------1 M_Type1 200 8002 M_Type2 1000 790i have one view follwoing is the view querySELECT PrimaryTable.LoanID, PrimaryTable.SelectedType, SValues.DescriptionFROM PrimaryTable INNER JOIN SValues ON PrimaryTable.SelectedOptionControlId = SValues.ValueCodeWHERE SValues.Table_Name = 'PrimaryTable' AND SValues.Column_Name = 'SelectedType'here SValues is a lookup table. Consider my view is returning following data2 LType1 NULLfrom same view I want to select LLoss and LNAV from table1 as my ype is LType1 so my final o/p of my view should be SELECT PrimaryTable.LoanID, PrimaryTable.SelectedType, SValues.Description, Loss, NAVFROM PrimaryTable INNER JOIN SValues ON PrimaryTable.SelectedOptionControlId = SValues.ValueCodeWHERE SValues.Table_Name = 'PrimaryTable' AND SValues.Column_Name = 'SelectedType'O/P2 LType1 NULL 100 800My Loss and NAV value is depend on the value of current view query.Plz tell me how I can get Loss and Nav in same view?SQLTeam |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-19 : 10:55:24
|
| [code]SELECT PrimaryTable.LoanID,PrimaryTable.SelectedType,SValues.Description,tmp.Val,tmp.NAVFROM PrimaryTableINNER JOIN SValuesONPrimaryTable.SelectedOptionControlId = SValues.ValueCodeWHERE SValues.Table_Name = 'PrimaryTable'ANDSValues.Column_Name = 'SelectedType'LEFT JOIN (SELECT LID AS ID, LType AS Type, LLoss AS Val, LNAV AS NAV FROM table1 UNION ALL SELECT MID MType MLoss MNAV FROM table2) tmpON tmp.Type=PrimaryTable.SelectedType[/code] |
 |
|
|
|
|
|
|
|