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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql query

Author  Topic 

sundayose
Starting Member

21 Posts

Posted - 2013-08-09 : 11:17:01
Dear members I have a query below;

use DBMUST
select
[dbo].[tbl_VOUCHER_CAPTURE].dt_VOUCHER_ISSUE_DATE AS Sales_Date,
[dbo].[tbl_VOUCHER_CAPTURE_DETAIL].str_BARCODE AS Voucher,
[dbo].[tbl_SALES_TEAM_MASTER].str_SALES_TEAM_NAME AS Team,
[dbo].[tbl_SALES_EXECUTIVE_MASTER].[str_SALES_EXECUTIVE_NAME] AS BCC,
[dbo].[tbl_DISTRIBUTOR_MASTER].[str_DISTRIBUTOR_NAME]AS CBD,
[dbo].[tbl_DISTRICT_MASTER].str_DISTRICT_NAME AS CBD_District,
[dbo].[tbl_VOUCHER_ISSUE].[dt_VOUCHER_ISSUE_DATE] AS Issuance_Date

from [dbo].[tbl_VOUCHER_CAPTURE]

left Join [dbo].[tbl_VOUCHER_CAPTURE_DETAIL]
on [dbo].[tbl_VOUCHER_CAPTURE].int_VOUCHER_CAPTURE_ID = [dbo].[tbl_VOUCHER_CAPTURE_DETAIL].int_VOUCHER_CAPTURE_ID
Left Join [dbo].[tbl_SALES_EXECUTIVE_MASTER]
on [dbo].[tbl_VOUCHER_CAPTURE].int_SALES_EXECUTIVE_ID = [dbo].[tbl_SALES_EXECUTIVE_MASTER].int_SALES_EXECUTIVE_ID
Left Join [dbo].[tbl_DISTRIBUTOR_MASTER]
on [dbo].[tbl_VOUCHER_CAPTURE].int_DISTRIBUTOR_ID = [dbo].[tbl_DISTRIBUTOR_MASTER].int_DISTRIBUTOR_ID
Left Join [dbo].[tbl_VOUCHER_ISSUE]
On [dbo].[tbl_VOUCHER_CAPTURE_DETAIL].[int_VOUCHER_ISSUE_ID] = [dbo].[tbl_VOUCHER_ISSUE].[int_VOUCHER_ISSUE_ID]
Left Join [dbo].[tbl_VOUCHER_ISSUE_DETAIL]
On [dbo].[tbl_VOUCHER_CAPTURE_DETAIL].int_VOUCHER_ISSUE_DETAIL_ID = [dbo].[tbl_VOUCHER_ISSUE_DETAIL].int_VOUCHER_ISSUE_DETAIL_ID
Left Join [dbo].[tbl_SALES_TEAM_MASTER]
ON [dbo].[tbl_VOUCHER_ISSUE].int_SALES_TEAM_ID = [dbo].[tbl_SALES_TEAM_MASTER].int_SALES_TEAM_ID
Left Join [dbo].[tbl_DISTRICT_MASTER]
ON [dbo].[tbl_DISTRIBUTOR_MASTER].int_DISTRICT_ID = [dbo].[tbl_DISTRICT_MASTER].int_DISTRICT_ID

Where
[dbo].[tbl_VOUCHER_CAPTURE_DETAIL].str_BARCODE Like 'FPUG%'

when I run this code I get an output but for some vouchers, the CB and District output are wrong.
Can some one advise me where am i am going with my query.

Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-11 : 17:08:02
Could be many things.
1) Your join is wrong
2) The table could contain wrong data



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -