获取文本而不是 ID
Get text instead of ID
我有一个查询,其中我得到 Department_Id
作为 812 它的整数值。我在另一个 table 中用文本引用了这个 ID,它是
select type_desc from type_mst_a where master_mkey = 812
我的查询是
select convert(varchar(15),doc_Date,103)Doc_Dates,department_id,
case outward_Type when 'N' then 'None' when 'P' then 'Private' when 'C' then 'Confidential'
end [Type], convert(varchar(15),ref_date,103) Ref_dates, convert(varchar(15),Updated_Bill_Date,103)Updated_Bill_Dates ,
convert(varchar(15), Due_Date,103)Due_dates,* from view_A_Inward_Doc_Tracking_Hdr
where delete_flag='N' and mkey= 227381
如何获取该 ID 的值?
您可以使用子 select 将 department_id
转换为文本,如下所示:
select convert(varchar(15), doc_Date, 103) Doc_Dates,
(select type_desc from type_mst_a where master_mkey = department_id),
...
或者,您可以加入 table type_mst_a
。
select convert(varchar(15), doc_Date, 103) Doc_Dates,
department_id,
text.type_desc,
case outward_Type when 'N' then 'None' when 'P' then 'Private' when 'C' then 'Confidential' end [Type],
convert(varchar(15), ref_date, 103) Ref_dates,
convert(varchar(15), Updated_Bill_Date,103) Updated_Bill_Dates,
convert(varchar(15), Due_Date, 103) Due_dates,
*
from view_A_Inward_Doc_Tracking_Hdr INWARD
left outer join type_mst_a text on text.master_mkey = department_id
where INWARD.delete_flag = 'N'
and mkey = 227381
外连接保证 - 如果找不到 suitable 文本 - 查询结果不会消失。
我有一个查询,其中我得到 Department_Id
作为 812 它的整数值。我在另一个 table 中用文本引用了这个 ID,它是
select type_desc from type_mst_a where master_mkey = 812
我的查询是
select convert(varchar(15),doc_Date,103)Doc_Dates,department_id,
case outward_Type when 'N' then 'None' when 'P' then 'Private' when 'C' then 'Confidential'
end [Type], convert(varchar(15),ref_date,103) Ref_dates, convert(varchar(15),Updated_Bill_Date,103)Updated_Bill_Dates ,
convert(varchar(15), Due_Date,103)Due_dates,* from view_A_Inward_Doc_Tracking_Hdr
where delete_flag='N' and mkey= 227381
如何获取该 ID 的值?
您可以使用子 select 将 department_id
转换为文本,如下所示:
select convert(varchar(15), doc_Date, 103) Doc_Dates,
(select type_desc from type_mst_a where master_mkey = department_id),
...
或者,您可以加入 table type_mst_a
。
select convert(varchar(15), doc_Date, 103) Doc_Dates,
department_id,
text.type_desc,
case outward_Type when 'N' then 'None' when 'P' then 'Private' when 'C' then 'Confidential' end [Type],
convert(varchar(15), ref_date, 103) Ref_dates,
convert(varchar(15), Updated_Bill_Date,103) Updated_Bill_Dates,
convert(varchar(15), Due_Date, 103) Due_dates,
*
from view_A_Inward_Doc_Tracking_Hdr INWARD
left outer join type_mst_a text on text.master_mkey = department_id
where INWARD.delete_flag = 'N'
and mkey = 227381
外连接保证 - 如果找不到 suitable 文本 - 查询结果不会消失。