I was looking through our vendors views, searching for something I
needed for our Datawarehouse and I came across something I do not
understand: I found a view that lists data when I use it in t-sql,
however when I try to use the statement when I modified the view (via
MS SQL Server Management Studio) I can not execute the statement. I get
The column prefix 'dbo.tbl_5001_N umericAudit' does not match with a
table name or alias name used in the query.
Upon closer inspection, I found two ON for the inner join, which I dont
think is correct.
So, how can the view work, but not the SQL that defines the view?
SQL Server 2000, up to date patches:
SELECT dbo.tbl_5001_Nu mericAudit.aEve ntID,
dbo.tbl_5001_Nu mericAudit.nPar entEventID,
dbo.tbl_5001_Nu mericAudit.nUse rID,
dbo.tbl_5001_Nu mericAudit.nCol umnID,
dbo.tbl_5001_Nu mericAudit.nKey ID,
dbo.tbl_5001_Nu mericAudit.dCha ngeTime,
CAST(dbo.tbl_50 01_NumericAudit .vToValue AS
nVarchar(512)) AS vToValue, dbo.tbl_5001_Nu mericAudit.nCha ngeMode,
dbo.tbl_5001_Nu mericAudit.tChi ldEventText, CASE
WHEN nConstraintType = 3 THEN 5 ELSE tblColumnMain.n DataType END AS
nDataType,
dbo.tbl_5001_Nu mericAudit.nID,
CAST(dbo.tbl_50 01_NumericAudit .vFromValue AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_Nu mericAudit WITH (NOLOCK) LEFT OUTER JOIN
dbo.tblColumnMa in WITH (NoLock) INNER JOIN
--
-- Posters comment: here is the double ON
--
dbo.tblCustomFi eld WITH (NoLock) ON
dbo.tblColumnMa in.aColumnID = dbo.tbl_5001_Nu mericAudit.nCol umnID ON
dbo.tbl_5001_Nu mericAudit.nCol umnID =
dbo.tblCustomFi eld.nColumnID LEFT OUTER JOIN
dbo.tblConstrai nt WITH (NOLOCK) ON
dbo.tblCustomFi eld.nConstraint ID = dbo.tblConstrai nt.aConstraintI D AND
(dbo.tblConstra int.nConstraint Type = 4 OR
dbo.tblConstrai nt.nConstraintT ype = 9 OR
dbo.tblConstrai nt.nConstraintT ype = 3)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(CAST(vToVa lue AS decimal(19, 6)) AS nVarchar(512)) AS
vToValue,
nChangeMode, tChildEventText , 5 AS nDataType,
nID, CAST(CAST(vFrom Value AS decimal(19, 6)) AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_Fl oatAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(vToValue AS nVarchar(512)) AS vToValue, nChangeMode,
tChildEventText , 2 AS nDataType, nID,
CAST(vFromValue AS nVarchar(512)) AS vFromValue
FROM dbo.tbl_5001_St ringAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CONVERT(nVarcha r(512), vToValue, 121) AS vToValue,
nChangeMode,
tChildEventText , 3 AS nDataType, nID,
CONVERT(nVarcha r(512), vFromValue, 121) AS vFromValue
FROM dbo.tbl_5001_Da teAudit WITH (NOLOCK)
needed for our Datawarehouse and I came across something I do not
understand: I found a view that lists data when I use it in t-sql,
however when I try to use the statement when I modified the view (via
MS SQL Server Management Studio) I can not execute the statement. I get
The column prefix 'dbo.tbl_5001_N umericAudit' does not match with a
table name or alias name used in the query.
Upon closer inspection, I found two ON for the inner join, which I dont
think is correct.
So, how can the view work, but not the SQL that defines the view?
SQL Server 2000, up to date patches:
SELECT dbo.tbl_5001_Nu mericAudit.aEve ntID,
dbo.tbl_5001_Nu mericAudit.nPar entEventID,
dbo.tbl_5001_Nu mericAudit.nUse rID,
dbo.tbl_5001_Nu mericAudit.nCol umnID,
dbo.tbl_5001_Nu mericAudit.nKey ID,
dbo.tbl_5001_Nu mericAudit.dCha ngeTime,
CAST(dbo.tbl_50 01_NumericAudit .vToValue AS
nVarchar(512)) AS vToValue, dbo.tbl_5001_Nu mericAudit.nCha ngeMode,
dbo.tbl_5001_Nu mericAudit.tChi ldEventText, CASE
WHEN nConstraintType = 3 THEN 5 ELSE tblColumnMain.n DataType END AS
nDataType,
dbo.tbl_5001_Nu mericAudit.nID,
CAST(dbo.tbl_50 01_NumericAudit .vFromValue AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_Nu mericAudit WITH (NOLOCK) LEFT OUTER JOIN
dbo.tblColumnMa in WITH (NoLock) INNER JOIN
--
-- Posters comment: here is the double ON
--
dbo.tblCustomFi eld WITH (NoLock) ON
dbo.tblColumnMa in.aColumnID = dbo.tbl_5001_Nu mericAudit.nCol umnID ON
dbo.tbl_5001_Nu mericAudit.nCol umnID =
dbo.tblCustomFi eld.nColumnID LEFT OUTER JOIN
dbo.tblConstrai nt WITH (NOLOCK) ON
dbo.tblCustomFi eld.nConstraint ID = dbo.tblConstrai nt.aConstraintI D AND
(dbo.tblConstra int.nConstraint Type = 4 OR
dbo.tblConstrai nt.nConstraintT ype = 9 OR
dbo.tblConstrai nt.nConstraintT ype = 3)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(CAST(vToVa lue AS decimal(19, 6)) AS nVarchar(512)) AS
vToValue,
nChangeMode, tChildEventText , 5 AS nDataType,
nID, CAST(CAST(vFrom Value AS decimal(19, 6)) AS nVarchar(512)) AS
vFromValue
FROM dbo.tbl_5001_Fl oatAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CAST(vToValue AS nVarchar(512)) AS vToValue, nChangeMode,
tChildEventText , 2 AS nDataType, nID,
CAST(vFromValue AS nVarchar(512)) AS vFromValue
FROM dbo.tbl_5001_St ringAudit WITH (NOLOCK)
UNION ALL
SELECT aEventID, nParentEventID, nUserID, nColumnID, nKeyID,
dChangeTime, CONVERT(nVarcha r(512), vToValue, 121) AS vToValue,
nChangeMode,
tChildEventText , 3 AS nDataType, nID,
CONVERT(nVarcha r(512), vFromValue, 121) AS vFromValue
FROM dbo.tbl_5001_Da teAudit WITH (NOLOCK)
Comment