sql server - I need to do a view in sql that returns the latest invoice date for each company -


After

I think that is dbo.companies and a company table is companyId As a column I have an invoice table which is the invoicecompanyId column with dbo.invoices (which will be replaced by companyId And it also has a column called invoice . Any companies I am trying to achieve, they will have every companyid with the latest code for all companies. A scene of Land.

I did the following but I do not know how to filter for the latest invoice, it returns all the invoices of all companies and I need the latest invoice for all companies

< Pre> SELECT TOP (100) PERCENT 'A' + SUBSTRING ('000000', 1, 6 - LEN (varchar (10)) as cast (dbo.companies.companyId) + cast (dbo.companies In the form of .companyId varchar (10)) as client_id, dbo.invoices.invoice.date include interiors from dbo.invo_Date as S_Inv_Date

  select SUBSTRING ('000000', 1, 6 - LEN (CAST (dbo.companies.companyId as varchar (10))) + CAST (Dbo.companies.companyId AS varchar (10)) AS Client_ID, BMXD MaxEviec EDATE from dbo.companies C, (dbo.invoices.invoiceCompanyId by dbo.invoices Group selection dbo.invoices.invoiceCompanyId companyId, Max ( Dbo.invoices.invoiceDate) mxDate) b Where c.companyId = b.companyId by order1  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -