2011-09-09 61 views
0

我有一個用來查詢,如下所示:如何在查詢中顯示帶結果集的表名?

SELECT LTRIM(RTRIM(ClaimsAdminName)) + ' | ' + LTRIM(RTRIM(ClaimsAdminID)) AS Clientname 
FROM tblClaimsAdmin 
WHERE (ClaimsAdminName LIKE @Prefix) 
UNION 
SELECT LTRIM(RTRIM(EmployerFName + ' ' + EmployerLName)) + ' | ' + LTRIM(RTRIM(EmployerID)) AS Clientname 
FROM tblEmployer 
WHERE (EmployerFName LIKE @Prefix) 

結果返回,如果我輸入 'S%' 是:

S | 8 Sumit Singh | 16

現在有什麼辦法,以便我可以返回表名與結果集。就像從哪個表值的價值。

我希望我清楚我的查詢。

請幫忙!

感謝

Swaroop Kumar.P

回答

0
select 'table1' as tablename, otherfields 
from table1 
union all 
select 'table2', otherfields 
from table2