Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Linked server query column needed


Linked server query column needed

Author
Message
johnnyrmtl
johnnyrmtl
SSC-Enthusiastic
SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)

Group: General Forum Members
Points: 121 Visits: 429
Hello all,

Pardon my ignorance ... but i'm trying to add a column in my linked server query which is where the records are coming from. I would need a the target name, in this case it's the [linked server]

This is a sp_who2 executed with a linked server.

SELECT
--@@servername
-- D.text SQLStatement,
--A.Session_ID SPID,
--ISNULL(B.status,A.status) Status,
distinct A.login_name Login, A.host_name 'Originating HostName',
--C.BlkBy,
DB_NAME(B.Database_ID) DBName, B.command,
--ISNULL(B.cpu_time, A.cpu_time) CPUTime,
--ISNULL((B.reads + B.writes),(A.reads + A.writes)) DiskIO,
--A.last_request_start_time LastBatch,
A.program_name

FROM [linked server].master.sys.dm_exec_sessions A
LEFT JOIN [linked server].master.sys.dm_exec_requests B
ON A.session_id = B.session_id
LEFT JOIN (SELECT A.request_session_id SPID, B.blocking_session_id BlkBy
FROM [linked server].master.sys.dm_tran_locks as A
INNER JOIN [linked server].master.sys.dm_os_waiting_tasks
as B ON A.lock_owner_address = B.resource_address) C
ON A.Session_ID = C.SPID
OUTER APPLY master.sys.dm_exec_sql_text(sql_handle) D
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
Can't you just hard-code the string in the Select?

select 'Linked Server Name' as LinkedServerName
from [LinkedServer].database.schema.object;



- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
johnnyrmtl
johnnyrmtl
SSC-Enthusiastic
SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)

Group: General Forum Members
Points: 121 Visits: 429
This will work I guess , although I would like the column at the beginning...

SELECT
distinct A.login_name Login, A.host_name 'Originating HostName',
DB_NAME(B.Database_ID) DBName, B.command,
A.program_name,
data_source as 'Linked Server Name'
FROM [linked].master.sys.dm_exec_sessions A
LEFT JOIN [linked].master.sys.dm_exec_requests B
ON A.session_id = B.session_id
LEFT JOIN (SELECT A.request_session_id SPID, B.blocking_session_id BlkBy
FROM [linked].master.sys.dm_tran_locks as A
INNER JOIN [linked].master.sys.dm_os_waiting_tasks
as B ON A.lock_owner_address = B.resource_address) C
ON A.Session_ID = C.SPID
OUTER APPLY master.sys.dm_exec_sql_text(sql_handle) D,
--Add column from target linked server
[linked].master.sys.servers
johnnyrmtl
johnnyrmtl
SSC-Enthusiastic
SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)SSC-Enthusiastic (121 reputation)

Group: General Forum Members
Points: 121 Visits: 429
Actually it doesn't work as it lists back all linked servers on the specific server Sad
I just need the server where i'm receiving the info from...

thanks
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search