Author |
Topic |
sureshprpt
Starting Member
33 Posts |
Posted - 2013-02-18 : 11:57:29
|
Hi, I have two tables , in the first table Itemcode and qty are available and in another cost are available .But the issue is , In the cost table i have two cost method based on my inventory cost 02&07.Now i want 07 cost for the itemcode available in table.In some codes, 07 cost was not available in the table 2. If write the query for this report, If the code not having the 07 cost in the table 2 was not appearing in the report.But if is not available , cost should be 0 in the report.request to provide the query to my report. The examples are mentioned below with my outputTable 1Code_no Qty123 1124 3125 6Table 2Code_no Cost_type Cost123 07 45123 02 10124 02 5125 02 10125 07 15My out put isCode_no qty 07Cost123 1 45124 3 0125 6 15ThanksRegardsSureshThanks & RegardsSuresh |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-18 : 12:18:00
|
[code]SELECT a.Code_no, a.Qty, ISNULL(b.Cost,0) AS [07Cost]FROM Table1 a LEFT JOIN Table2 b ON a.Code_no = b.Code_no AND b.Cost_type = '07';[/code] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-18 : 12:18:32
|
[code]SELECT t1.*, COALESCE(t2.Cost,0) AS CostFROM table1 t1LEFT JOIN table2 t2On t2.Code_no = t1.Code_noAND t2.Cost_type='07'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sureshprpt
Starting Member
33 Posts |
Posted - 2013-02-18 : 12:29:49
|
Hi Visakh,This is my query SELECT F3111.WMDOCO,F3111.WMDCTO,F3111.WMCPIT,F3111.WMCPIL,F3111.WMUORG/1000,F3111.WMTRQT/1000,F3111.WMUM,COALESCE(F4105.COUNCS,0) FROM P2DTAA/F3111 LEFT JOIN F4105 ON F3111.WMMCU=F4105.COMCU AND F3111.WMCPIT = F4105.COITM WHERE (F3111.WMDCTO = 'W2') AND (F3111.WMMCU LIKE '%ITM') AND (F3111.WMDOCO = 13600191)AND (F4105.COLEDG ='07').Bus still code which not contain 07 cost was not appeared in the report.Thanks BysureshThanks & RegardsSuresh |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-18 : 12:34:03
|
it should beSELECT F3111.WMDOCO,F3111.WMDCTO,F3111.WMCPIT,F3111.WMCPIL,F3111.WMUORG/1000,F3111.WMTRQT/1000,F3111.WMUM,COALESCE(F4105.COUNCS,0) FROM P2DTAA/F3111 LEFT JOIN F4105 ON F3111.WMMCU=F4105.COMCU AND F3111.WMCPIT = F4105.COITM AND (F4105.COLEDG ='07'WHERE (F3111.WMDCTO = 'W2') AND (F3111.WMMCU LIKE '%ITM') AND (F3111.WMDOCO = 13600191)). ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
sureshprpt
Starting Member
33 Posts |
Posted - 2013-02-18 : 12:40:14
|
Thanks Visakh,Now i can able to capture in my report.Let me know your email ID , if any doubts i will send mail directly to you .ThanksSureshThanks & RegardsSuresh |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-18 : 12:43:25
|
you can post it here itself as that will make sure other experts can also see and give you quick solution even if I'm not available.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|