我有一个使用过的查询如下:
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
现在有什么方法可以让我返回带有结果集的tablename。就像值来自哪个表一样。
我希望我的查询清楚。
请帮忙!
由于
Swaroop Kumar.P
答案 0 :(得分:0)
select 'table1' as tablename, otherfields
from table1
union all
select 'table2', otherfields
from table2