我想要做的是提交用户名(或名称的一部分,即LIKE)并返回Description(Variable.Value表)和文档文件名(Documents表)。最新修订版。我这样做是为了获得最新的转速并取得巨大成功。我已经尝试了无数种方法来插入作者名称(variablevalue表)以获得我所追求的内容。我尝试了一个没有运气的子查询。我认为复合键正在抓住我,因为我还没有完成复合键的大量工作。 TIA。
Select Distinct vv.ValueCache
from VariableValue vv, Documents d
where d.filename like 'ECO-%' and d.deleted = 0 and d.DocumentID = vv.DocumentID and
vv.VariableID = ( Select VariableID
from Variable
where VariableName like 'Description') and
vv.RevisionNo = ( Select Max( Vv1.RevisionNo )
From VariableValue vv1
where vv1.VariableID = vv.VariableID and
vv1.DocumentID = d.DocumentID and
vv1.ValueText is not null ) and
vv.ValueCache != ''
order by vv.ValueCache ASC
这是Documents表缺少的DDL。
USE [PDM_NT_Vault]
GO
/****** Object: Table [dbo].[Documents] Script Date: 9/29/2017 9:51:40 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Documents](
[DocumentID] [int] IDENTITY(1,1) NOT NULL,
[Filename] [nvarchar](255) NULL,
[LockProject] [int] NULL CONSTRAINT [DF__TemporaryU__Mode__3B75D760] DEFAULT ((2)),
[UserID] [int] NULL CONSTRAINT [DF__Temporary__UserI__3C69FB99] DEFAULT ((0)),
[LockDomain] [nvarchar](255) NULL,
[LockPath] [nvarchar](255) NULL,
[Busy] [bit] NOT NULL CONSTRAINT [DF__TemporaryU__Busy__3E52440B] DEFAULT ((0)),
[Flushed] [int] NULL CONSTRAINT [DF_Documents_Flushed] DEFAULT ((1)),
[DefValStored] [int] NULL CONSTRAINT [DF_Documents_DefValStored] DEFAULT ((0)),
[RevGenCounter] [int] NULL,
[LatestRevisionNo] [int] NULL,
[CurrentStatusID] [int] NULL,
[WorkingVersionModified] [int] NULL,
[ExtensionID] [int] NULL CONSTRAINT [DF_Documents_ExtensionID] DEFAULT ((1)),
[LockDate] [datetime] NULL,
[UserDocRefsModified] [bit] NULL,
[Deleted] [bit] NOT NULL CONSTRAINT [DF_Documents_Deleted] DEFAULT ((0)),
[Shared] [int] NULL CONSTRAINT [DF_Documents_Shared] DEFAULT ((0)),
[LockViewID] [uniqueidentifier] NULL,
[Link] [bit] NULL CONSTRAINT [DF_Documents_Link] DEFAULT ((0)),
[DocTypeID] [int] NULL,
[ObjectTypeID] [int] NULL CONSTRAINT [DF_Documents_ObjectTypeID] DEFAULT ((1)),
[Flags] [int] NOT NULL CONSTRAINT [DF_Documents_Flags] DEFAULT ((0)),
CONSTRAINT [aaaaaDocuments1_PK] PRIMARY KEY CLUSTERED
(
[DocumentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Documents] WITH NOCHECK ADD CONSTRAINT [Documents_FK00] FOREIGN KEY([UserID])
REFERENCES [dbo].[Users] ([UserID])
GO
ALTER TABLE [dbo].[Documents] CHECK CONSTRAINT [Documents_FK00]
GO
ALTER TABLE [dbo].[Documents] WITH NOCHECK ADD CONSTRAINT [FK_Documents_DocType] FOREIGN KEY([DocTypeID])
REFERENCES [dbo].[DocType] ([DocTypeID])
GO
ALTER TABLE [dbo].[Documents] CHECK CONSTRAINT [FK_Documents_DocType]
GO
ALTER TABLE [dbo].[Documents] WITH NOCHECK ADD CONSTRAINT [FK_Documents_FileExtension] FOREIGN KEY([ExtensionID])
REFERENCES [dbo].[FileExtension] ([ExtensionID])
GO
ALTER TABLE [dbo].[Documents] CHECK CONSTRAINT [FK_Documents_FileExtension]
GO
ALTER TABLE [dbo].[Documents] WITH NOCHECK ADD CONSTRAINT [FK_Documents_ObjectType] FOREIGN KEY([ObjectTypeID])
REFERENCES [dbo].[ObjectType] ([ObjectTypeID])
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[Documents] CHECK CONSTRAINT [FK_Documents_ObjectType]
GO
ALTER TABLE [dbo].[Documents] WITH CHECK ADD CONSTRAINT [FK_Documents_Projects1] FOREIGN KEY([LockProject])
REFERENCES [dbo].[Projects] ([ProjectID])
GO
ALTER TABLE [dbo].[Documents] CHECK CONSTRAINT [FK_Documents_Projects1]
GO