I have created new table in my database called T_AD_Data, when I am trying to join the table to V_ALL. getting error.
SELECT case V_ALL.JOB_qty_BlankPages when 0
then V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + (V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages)))
else
V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages + V_ALL.JOB_qty_BlankPages
end as PrintedPages,V_ALL.JOB_qty_BWPages as BWPages,V_ALL.JOB_qty_ColorPages as ColorPages,
case V_ALL.JOB_qty_BlankPages when 0 then
V_ALL.JOB_qty_BlankPages + ((V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages * 2) - (V_ALL.JOB_qty_BWPages + V_ALL.JOB_qty_ColorPages))
else V_ALL.JOB_qty_BlankPages
end as BlankPages,V_ALL.JOB_qty_SimplexPages as SimplexPages,
V_ALL.JOB_qty_DuplexPages * 2 as DuplexPages,
V_ALL.JOB_qty_SimplexPages + V_ALL.JOB_qty_DuplexPages as TotalSheets,V_All.JOB_lab_NTDomainName, V_All.Lab_GroupName, V_All.JOB_lab_NTUserName, V_All.Lab_NTFullUserName, V_All.PRINTER_lab_Location, V_All.JOB_lab_DocumentName, V_All.JOB_qty_Size, V_All.JOB_qty_Copies, V_All.JOB_date_Submitted, T_AD_Data.lab_sAMAccountName, T_AD_Data.lab_department, T_AD_Data.lab_physicalDeliveryOfficeName FROM V_ALL JOIN T_AD_Data AD_Data ON V_ALL.JOB_lab_NTUserName=T_AD_Data.lab_displayName;
Results:
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_displayName" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_sAMAccountName" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_department" could not be bound.
Msg 4104, Level 16, State 1, Line 33
The multi-part identifier "T_AD_Data.lab_" could not be bound.
答案 0 :(得分:0)
The Prefix T_AD_Data
doesn't exist anywhere. You're attempting to use it in your join, but have no table named or aliased as such anywhere else in your FROM
clause. Same goes for the last three fields of your SELECT
.
It looks like either T_SBIL_AD_Data
should be aliased as T_AD_Data
(instead of SBIL_AD_Data)
, or you are you missing an entire table / view from your FROM
clause.
EDIT: Using additional info from your comment, the answer is there is a table T_AD_Data
that has columns you are referencing in both your SELECT
and JOIN
but the table is not anywhere in the FROM
clause.
What you need is for your FROM clause to be something like this...
FROM
V_ALL
<SOME SORTA> JOIN T_AD_Data ON V_ALL.<Some_Field_In_V_All> = T_AD_Data.<Some_Field_In_T_AD_Data>
JOIN T_SBIL_AD_Data SBIL_AD_Data ON V_ALL.JOB_lab_NTUserName = T_AD_Data.lab_displayName
To be clear, <SOME SORTA>
is a placeholder for whatever type of JOIN makes the most sense based on your actual data and the desired result (i.e. LEFT OUTER
, INNER
, etc.).
Also V_ALL.<Some_Field_In_V_All>
and T_AD_Data.<Some_Field_In_T_AD_Data>
are pseudocode placeholders for actual fields from each of those respective tables. Based on the field names you provided, maybe V_All.Lab_NTFullUserName
and T_AD_Data.lab_sAMAccountName
, but that's not much more than a guess.