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 |
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-02-20 : 07:39:21
|
| I have two views.The code for the first view is this one :SELECT bedalog, tmpRm, SUM(bedaposo) AS rbedaposoFROM ErmisUser.QBEPROKWHERE (bedaflarr = '1') AND (LEFT(bedakind, 1) <> 'P')GROUP BY bedalog, tmpRmThe code for the second view is this one :SELECT bedalog, tmpRm, SUM(bedaposo) AS rbedaposo1FROM ErmisUser.QBEPROKWHERE (bedaflarr <> '1') AND (LEFT(bedakind, 1) <> 'P')GROUP BY bedalog, tmpRmI want to create a view that will have the following columns :bedalog, tmpRm, rbedaposo, rbedaposo1, rbedaposo + rbedaposo1for every record of the previous two viewswhere it is not have a value it should show 0.Thnx a lot! |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-20 : 07:47:53
|
Something like this?Select bedalog, tmpRm, sum(rbedaposo) as rbedaposo, sum(rbedaposo1) as rbedaposo1, sum(rbedaposo+rbedaposo1) as rbedaposo_TotalFrom(SELECT bedalog, tmpRm, rbedaposo, 0 as rbedaposo1from view1union allSELECT bedalog, tmpRm, 0 as rbedaposo, rbedaposo1from view2) tGroup by bedalog, tmpRm Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-02-20 : 07:51:53
|
| Msg 207, Level 16, State 1, Line 8Invalid column name 'bedaposo1'. |
 |
|
|
skiabox
Posting Yak Master
169 Posts |
Posted - 2008-02-21 : 06:46:09
|
| Can you tell me why I get this error?Thnx again! |
 |
|
|
vitoco
Starting Member
22 Posts |
Posted - 2008-02-21 : 08:31:53
|
quote:
1: Select 2: bedalog, tmpRm, sum(rbedaposo) as rbedaposo, sum(rbedaposo1) as rbedaposo1, sum(rbedaposo+rbedaposo1) as rbedaposo_Total 3: From 4: ( 5: SELECT bedalog, tmpRm, rbedaposo, 0 as rbedaposo1 6: from view1 7: union all 8: SELECT bedalog, tmpRm, 0 as rbedaposo, rbedaposo1 9: from view210: ) t11: Group by bedalog, tmpRm
Just guessing... |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-21 : 08:33:09
|
quote: Originally posted by vitoco
quote:
1: Select 2: bedalog, tmpRm, sum(rbedaposo) as rbedaposo, sum(rbedaposo1) as rbedaposo1, sum(rbedaposo+rbedaposo1) as rbedaposo_Total 3: From 4: ( 5: SELECT bedalog, tmpRm, rbedaposo, 0 as rbedaposo1 6: from view1 7: union all 8: SELECT bedalog, tmpRm, 0 as rbedaposo, rbedaposo1 9: from view210: ) t11: Group by bedalog, tmpRm
Just guessing... 
I already made correction to my earlier reply, in case you haven't noticed.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
vitoco
Starting Member
22 Posts |
Posted - 2008-02-21 : 08:43:05
|
| I didn't notice... it seems that neither skiabox, he posted a second reply 1 day later. |
 |
|
|
|
|
|
|
|