I asked this question of Bard and Bing chat, but they gave me conflicting answers. Maybe they are both wrong. So here goes:
Write a SQL Server 2019 stored procedure for getting a list of invoices in table INVOICES which is ordered by the earliest date in OPERATIONS.DBegin, based on the following schema:
CREATE TABLE [dbo].[INVLINES]
( [ID] [int] IDENTITY(1,1) NOT NULL,
[iInvoice] [int] NOT NULL,
[DService] [datetimeoffset](0) NOT NULL,
[iOperation] [int] NOT NULL)
GO
CREATE TABLE [dbo].[INVOICES]
( [ID] [int] IDENTITY(1,1) NOT NULL,
[DInvoice] [datetimeoffset](0) NULL,
[mTotalAmt] [money] NULL)
GO
CREATE TABLE [dbo].[OPERATIONS]
( [ID] [int] IDENTITY(70001,1) NOT NULL,
[DBegin] [smalldatetime] NULL)
GO
ALTER TABLE [dbo].[INVLINES] WITH CHECK ADD CONSTRAINT [FK_INVLINES_INVOICES] FOREIGN KEY([iInvoice]) REFERENCES [dbo].[INVOICES] ([ID])
GO
ALTER TABLE [dbo].[INVLINES] CHECK CONSTRAINT [FK_INVLINES_INVOICES]
GO
ALTER TABLE [dbo].[INVLINES] WITH CHECK ADD CONSTRAINT [FK_INVLINES_OPERATIONS] FOREIGN KEY([iOperation]) REFERENCES [dbo].[OPERATIONS] ([ID])
GO
ALTER TABLE [dbo].[INVLINES] CHECK CONSTRAINT [FK_INVLINES_OPERATIONS]
GO