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 |
|
studyy
Starting Member
16 Posts |
Posted - 2010-05-10 : 01:55:17
|
| HiI have 2 table which i want to join so it look like cash book.I m trying to make use of views1st table having 2 recordsBillIdDateAmount2nd Table having 2 recordsReceiptidDateAmountwhen i try to apply joinsThey return 4 rows , For Which I have no problemsbut the problem is that they dont contain null value,db fill them up from last value it have for that table.Billid Amount Date ReciptID Amount Date1 105 2010-02-15 1 200 2010-02-152 95 2010-02-15 1 200 2010-02-151 105 2010-02-15 2 50 2010-02-152 95 2010-02-15 2 50 2010-02-15Recipt data is changed :Billid Amount Date ReciptID Amount Date1 105 2010-02-15 1 200 2010-02-162 95 2010-02-15 1 200 2010-02-161 105 2010-02-15 2 50 2010-02-172 95 2010-02-15 2 50 2010-02-17you can see db is repeating value because it get 2 records.i want that repeated value are don't contain value & show as null only Like thisBillid Amount Date ReciptID Amount Date1 105 2010-02-15 Null Null Null2 95 2010-02-15 Null Null Null1 Null Null 1 200 2010-02-162 Null Null 2 50 2010-02-17Thank You |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-05-10 : 02:59:09
|
| Try with Full outer join.Refer this :http://msdn.microsoft.com/en-us/library/ms187518.aspxSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
studyy
Starting Member
16 Posts |
Posted - 2010-05-10 : 13:42:44
|
| HiThanks For Reply,I tried joins but i think i m not doing the right way so not getting the result i want .any one pls help.Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-10 : 14:28:37
|
| how will billid value repeat with receipt data?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lazerath
Constraint Violating Yak Guru
343 Posts |
Posted - 2010-05-10 : 16:28:31
|
| It's hard to understand what you really want here, so I'll guess. What about this:SelectBillId,NULL AS Receiptid,Date,AmountFROM Table1UNION ALLSELECTNULL AS BillID,Receiptid,Date,AmountFROM Table2Billid ReciptID Amount Date1 Null 105 2010-02-152 Null 95 2010-02-15Null 1 200 2010-02-16Null 2 50 2010-02-17 |
 |
|
|
studyy
Starting Member
16 Posts |
Posted - 2010-05-11 : 07:54:38
|
| Hi lazerathYou are a Gneiss.Can u explain the theory behind this sql ? Result i got is thisBillid ReciptID Date BillAmount 1 Null 2010-02-15 1052 Null 2010-02-15 95Null 1 2010-02-16 200Null 2 2010-02-17 50but one thing i want is to seperate the bill amount & ReceiptAmount currently they show under Bill Amount Here's what i want to getBillid ReciptID Date BillAmount ReceiptAmount1 Null 2010-02-15 105 Null2 Null 2010-02-15 95 NullNull 1 2010-02-16 Null 200Null 2 2010-02-17 Null 50Thanks AgainThank you very much. |
 |
|
|
lazerath
Constraint Violating Yak Guru
343 Posts |
Posted - 2010-05-11 : 16:30:38
|
| Look up "UNION" in Books Online and you should be able to figure out how to get your result. Hint: it requires an approach not unlike the one separating BillID and ReciptID. |
 |
|
|
|
|
|