Hi,
I needed to extract BOM in excel format using SQL. I refereed Queying SQL Database For Return All Parts In A Vault and it is super-useful. But it gives me only Parent and Child filenames in the output.
We use "Data-card" to populate meta information (e.g. Item Code) pertaining to each assembly and part file which is useful for our ERP. I need to augment above query to include Item code from the data card for each file in a separate column.
I could not figure out how to access data card information per file. How to go about that? Any help is greatly appreciated.
Thanks
Sameer Kelkar
Here is something that should help you out. It gets the Description variable for all files for @ configuration.
DECLARE @VariableName nvarchar(255)
DECLARE @ConfigName nvarchar(255)
SET @VariableName = 'Description'
SET @ConfigName = '@'
DECLARE @VariableID Int
DECLARE @ConfigID Int
SET @VariableID = (SELECT VariableID FROM Variable WHERE VariableName = @VariableName)
SET @ConfigID = (SELECT ConfigurationID FROM DocumentConfiguration WHERE ConfigurationName = @ConfigName)
SELECT d.Filename, @VariableName AS [Variable Name], @ConfigName AS [Configuration Name]
, vv.ValueText AS [Variable Value], d.LatestRevisionNo AS [Latest Version]
FROM VariableValue AS vv
JOIN Documents AS d ON vv.DocumentID = d.DocumentID
WHERE vv.VariableID = @VariableID
AND vv.ConfigurationID = @ConfigID
AND vv.RevisionNo = (SELECT MAX(vv1.RevisionNo) FROM VariableValue AS vv1
WHERE vv1.DocumentID = vv.DocumentID AND vv1.VariableID = @VariableID AND vv1.ConfigurationID = @ConfigID)