我有一个问题SQL Server 2000
,我需要从数据库中获取报告。我有一个数据库Automation
,它包含一组表来处理我们应用程序的票务过程的查询。
我需要从数据库中提取一份报告,该报告应包含票号和用户信息,例如谁输入、接收、编辑、查看了该票。
我需要数据库中的这些字段
Ticketnumber
billnumber
companyname
enteredby(username)
entereddate
recievedby(username)
recieveddate
editedby(Employeename)
editeddate
reviewedby(ReviewerName)
revieweddate
postedby(Managername)
posteddate
我有三张桌子
1>VPP_VendorBilldetails
BillentryID | ticketnumber | billnumber | VENDORNAME,BILLNUMBER,COSTCENTERNAME,BILLAMOUNT,TICKETDATE,BILLDATE | companyID(not companyname) | billdate | Enteredby(userid)| entereddate | recievedby(userid) | recieveddate | editedby(userid) | editeddate | reviewedby(userid) | revieweddate | postedby(userid) | posteddate
2>Users
UserID | employeeID | employeename |loginID| Password | usertype | status
3> VPP_ClientCompanyDetails
:
companyid | companyname | companyaddress | status
我已经写了这个查询,但我得到了所有三个类别的相同员工姓名:
SELECT CLIENTCOMPANYNAME, TICKETNUMBER,VENDORNAME,BILLNUMBER,COSTCENTERNAME,BILLAMOUNT,TICKETDATE,BILLDATE,
RECIEVEDDATE,EMPLOYEENAME AS EXECUTIVENAME,
VPP_VENDORBILLDETAILS.MODIFIEDDATE,
EMPLOYEENAME AS REVIEWERNAME,EMPLOYEENAME AS POSTEDBY,POSTEDDATE,ERRORCODE,
IMPACTCODE,ROOTCAUSE,REVIEWERREMARKS
FROM
VPP_VENDORBILLDETAILS
INNER JOIN
VPP_CLIENTCOMPANYDETAILS
ON VPP_VENDORBILLDETAILS.BILLENTEREDCOMPANYID = VPP_CLIENTCOMPANYDETAILS.CLIENTCOMPANYID
INNER JOIN USERS
ON VPP_VENDORBILLDETAILS.MODIFIEDBY = USERS.USERID
WHERE CONVERT(VARCHAR(12),CONVERT(DATETIME,POSTEDDATE,103),101)
BETWEEN CONVERT(DATETIME,CONVERT(VARCHAR(12),getdate()-7,100),101)
AND CONVERT(DATETIME,CONVERT(VARCHAR(12),getdate()-1,100),101)
AND VPP_CLIENTCOMPANYDETAILS.STATUS = 1 AND VPP_VENDORBILLDETAILS.STATUS = 1 AND USERS.STATUS = 1 AND ERRORCODE IS NOT NULL AND TALLYID IS NOT NULL
ORDER BY CLIENTCOMPANYNAME ASC
请检查并帮助我
请帮我提取上述表格的报告..