MS SQL Server StoreProc - Get Server Details
MS SQL Server StoreProc - Get Server Details
MS SQL Server StoreProc - Get Server Details
GO
/****** Object: StoredProcedure [dbo].[DCMON_ListAllBlocks] Script Date:
04/03/2012 23:13:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
AS
--
--------------------------------------------------------------------
/*
=====================PURPOSE=========================
=====================PAGE NAME(CALLING)==============
*/
--------------------------------------------------------------------
SET NOCOUNT ON
SET @DT=GETDATE()
select @DT dt,@@servername as Servername,db_name(qs.dbid) as
Dbname,Program_name,hostname,
cpu,blocked,spid AS [Victim Process
ID],physical_Io,memusage,login_time,loginame
,text
From sys.sysprocesses
as qs with(nolock)
CROSS APPLY sys.dm_exec_sql_text( qs.sql_handle) as st
where spid in (select blocked
from sys.sysprocesses
as qs with(nolock)
where blocked>0
)
GO
/****** Object: StoredProcedure [dbo].[s_SpaceUsed] Script Date: 04/03/2012
23:13:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
---------------------------------------------------
/*
EXEC s_SpaceUsed 'itsalertgenerator'
=====================PURPOSE=========================
TO GET THE DETAILS OF SPACES THAT HAS BEEN USED
AND UNUSED BY TABLES FOR A SPECIFIED DATABASE
=====================OUTPUT==========================
NONE
INPUT PARAM:
@SourceDB VARCHAR(128)
=====================PAGE NAME(CALLING)==============
=====================CREATED BY/DATE ================
Jay
13-10-2006
*/
-----------------------------------------------------
SET NOCOUNT ON
GO
/****** Object: StoredProcedure [dbo].[sp_readerrorlog] Script Date: 04/03/2012
23:13:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROc [dbo].[sp_readerrorlog]
(
@p1 INT = 0,
@p2 INT = NULL,
@p3 VARCHAR(255) = NULL,
@p4 VARCHAR(255) = NULL)
AS
BEGIN
IF (NOT IS_SRVROLEMEMBER(N'securityadmin') = 1)
BEGIN
RAISERROR(15003,-1,-1, N'securityadmin')
RETURN (1)
END
IF (@p2 IS NULL)
EXEC master.sys.xp_readerrorlog @p1
ELSE
EXEC master.sys.xp_readerrorlog @p1,@p2,@p3,@p4
END
GO
/****** Object: StoredProcedure [dbo].[sp_SDS] Script Date: 04/03/2012 23:13:04
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/
***********************************************************************************
***************
**
**
SELECT @BaseString =
' SELECT DB_NAME(), ' +
CASE WHEN @Ver = 'SQL 2000' THEN 'CASE WHEN status & 0x40 = 0x40 THEN ''Log'' ELSE
''Data'' END'
ELSE ' CASE type WHEN 0 THEN ''Data'' WHEN 1 THEN ''Log'' WHEN 4 THEN ''Full-
text'' ELSE ''reserved'' END' END +
', name, ' +
CASE WHEN @Ver = 'SQL 2000' THEN 'filename' ELSE 'physical_name' END +
', size*8.0/1024.0 FROM ' +
CASE WHEN @Ver = 'SQL 2000' THEN 'sysfiles' ELSE 'sys.database_files' END +
' WHERE '
+ CASE WHEN @Ver = 'SQL 2000' THEN ' HAS_DBACCESS(DB_NAME()) = 1' ELSE 'state_desc
= ''ONLINE''' END + '';
-- set used size for data files, do not change total obtained from
sys.database_files as it has for log files
UPDATE dbo.##Tbl_CombinedInfo
SET U = s.UsedExtents*8*8/1024.0
FROM dbo.##Tbl_CombinedInfo t JOIN dbo.##Tbl_DbFileStats s
ON t.LogicalName = s.Name AND s.DatabaseName = t.DatabaseName;
IF @Unit = 'GB'
UPDATE dbo.##Tbl_CombinedInfo
SET T = T / 1024, U = U / 1024, F = F / 1024;
SELECT CASE WHEN @Unit = 'GB' THEN 'GB' WHEN @Unit = 'KB' THEN 'KB' ELSE 'MB'
END AS 'SUM',
SUM (T) AS 'TOTAL', SUM (U) AS 'USED', SUM (F) AS 'FREE' FROM
dbo.##Tbl_CombinedInfo;
END
IF @Unit = 'KB'
UPDATE @Tbl_Final SET TOTAL = TOTAL * 1024,
used = used * 1024,
free = free * 1024,
Data = Data * 1024,
Data_Used = Data_Used * 1024,
Data_Free = Data_Free * 1024,
Log = Log * 1024,
Log_Used = Log_Used * 1024,
Log_Free = Log_Free * 1024;
IF @Unit = 'GB'
UPDATE @Tbl_Final SET TOTAL = TOTAL / 1024,
used = used / 1024,
free = free / 1024,
Data = Data / 1024,
Data_Used = Data_Used / 1024,
Data_Free = Data_Free / 1024,
Log = Log / 1024,
Log_Used = Log_Used / 1024,
Log_Free = Log_Free / 1024;
SELECT
CONVERT(dec(10, 2), TOTAL*100.0/@GrantTotal) AS 'WEIGHT (%)',
DatabaseName AS 'DATABASE',
CONVERT(VARCHAR(12), used) + ' (' + CONVERT(VARCHAR(12), [used (%)]) + ' %)'
AS 'USED (%)',
[+],
CONVERT(VARCHAR(12), free) + ' (' + CONVERT(VARCHAR(12), [free (%)]) + ' %)'
AS 'FREE (%)',
[=],
TOTAL,
[=],
CONVERT(VARCHAR(12), Data) + ' (' + CONVERT(VARCHAR(12), Data_Used) + ', '
+
CONVERT(VARCHAR(12), [Data_Used (%)]) + '%)' AS 'DATA (used, %)',
[+],
CONVERT(VARCHAR(12), Log) + ' (' + CONVERT(VARCHAR(12), Log_Used) + ', ' +
CONVERT(VARCHAR(12), [Log_Used (%)]) + '%)' AS 'LOG (used, %)'
FROM @Tbl_Final
WHERE DatabaseName LIKE ISNULL(@TargetDatabase, '%')
ORDER BY DatabaseName ASC;
IF @TargetDatabase IS NULL
SELECT CASE WHEN @Unit = 'GB' THEN 'GB' WHEN @Unit = 'KB' THEN 'KB' ELSE 'MB'
END AS 'SUM',
SUM (used) AS 'USED',
SUM (free) AS 'FREE',
SUM (TOTAL) AS 'TOTAL',
SUM (Data) AS 'DATA',
SUM (Log) AS 'LOG'
FROM @Tbl_Final;
END
RETURN (0)
GO
/****** Object: StoredProcedure [dbo].[sp_SOS] Script Date: 04/03/2012 23:13:05
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/
*==================================================================================
===============
Parameters:
@DbName: default is the current database
@SchemaName: default is null showing all schemas
@ObjectName: default is "%" including all objects in "LIKE" clause
@TopClause: default is null showing all objects. Can be "TOP N" or "TOP N
PERCENT"
@ObjectType: default is "S", "U", "V", "SQ" and "IT". All objects that can
be sized
@ShowInternalTable: default is "Yes", when listing IT, the Parent excludes it in
size
@OrderBy: default is by object name, can be any size related column
@UpdateUsage: default is 0, meaning "do not run DBCC UPDATEUSAGE"
Sample codes:
EXEC dbo.sp_SOS;
EXEC dbo.sp_SOS 'AdventureWorks', NULL, '%', NULL, 'U', 'No', 'T', 1;
sp_SOS 'TRACE', NULL, NULL, Null, ' ,,, ,;SQ,; u ;;;,, v ,,;iT , ;',
'No', N'N', 0;
sp_SOS NULL, NULL, NULL, NULL, 'U', 'Yes', N'U', 1;
sp_SOS 'AdventureWorks', 'Person%', 'Contact%', NULL, 'U', 'no', 'N', 0;
sp_SOS 'AdventureWorks', NULL, NULL, N'Top 100 Percent', 'S', 'yes', N'N', 1;
sp_SOS 'AdventureWorks', NULL, 'xml_index_nodes_309576141_32000', NULL, 'IT',
'yes', 'N', 1;
sp_SOS 'TRACE', NULL, 'Vw_DARS_217_overnight_activity_11142007', ' top 10 ',
'v', 'yes', 'N', 0;
sp_SOS 'AdventureWorks', NULL, 'xml%', ' top 10 ', null, 'yes', 'N', 1;
sp_SOS 'AdventureWorks2008', NULL, 'sales%', NULL, ' ,,; u ;;;,, v ', 'No',
N'N', 1;
sp_SOS NULL, NULL, NULL, N'Top 100 Percent', ' ;;Q, U;V,', N'Y', 1;
===================================================================================
==============*/
N'S, U, V, SQ, IT'), N' ', N''), N',', N''), N';', N''), N'SQ', N''),
N'U', N''),
N'V', N''), N'IT', N''), N'S', N'');
IF LEN(@OTV) <> 0 -- only allow comma, semi colon and space around S,U,V,SQ,IT
BEGIN
RAISERROR (N'Parameter error. Choose ''S'', ''U'', ''V'', ''SQ'', ''IT'' or any
combination of them,
separated by space, comma or semicolon.
N'''S'''),N'U',N'''U'''),N'V',N'''V'''),N'QQ',N'SQ'),N' ',N''),N'''''',N''',''')
END
SELECT
@WHERE_Type = CASE WHEN ISNULL(@ShowInternalTable, N'Yes') = N'Yes' THEN N't.DOT '
ELSE N't.POT ' END,
@SELECT = N'USE ' + @DbName + N'
SELECT ' + ISNULL(@TopClause, N'TOP 100 PERCENT ') +
N' CASE WHEN ''' + isnull(@ShowInternalTable, N'Yes') + N''' = ''Yes'' THEN
CASE t.DFN WHEN t.PFN THEN t.PFN
ELSE t.DFN + '' (''+ t.PFN + '')'' END ELSE t.PFN END AS ''Object Name'',
IF @Count = 0
BEGIN
RAISERROR (N'No records were found macthcing your criteria.', 16, 1)
RETURN (-1)
END
ELSE -- There're at least one records
BEGIN
-- Run DBCC UPDATEUSAGE to correct wrong values
IF ISNULL(@UpdateUsage, 0) = 1
BEGIN
SELECT @ObjectName = N'', @ID = 0
WHILE 1 = 1
BEGIN
SELECT TOP 1 @ObjectName = CASE WHEN [Object Name] LIKE N'%
(%' THEN
SUBSTRING([Object Name], 1, CHARINDEX(N'(', [Object Name])-2)
ELSE [Object Name] END
, @ID = ID FROM dbo.##FO WHERE ID > @ID ORDER BY ID ASC
IF @@ROWCOUNT = 0
BREAK
PRINT N'==> DBCC UPDATEUSAGE (' + @DbName + N', ''' + @ObjectName +
N''') WITH COUNT_ROWS'
DBCC UPDATEUSAGE (@DbName, @ObjectName) WITH COUNT_ROWS
PRINT N''
END
PRINT N''
TRUNCATE TABLE dbo.##FO
INSERT INTO dbo.##FO ([Object Name], [Type], [Rows], [Total(MB)],
[Unused(MB)],
[Used(MB)],[Index(MB)],[Data(MB)]) EXEC (@String)
END
ELSE
PRINT N'(Warning: Run "DBCC UPDATEUSAGE" on suspicious objects. It may incur
overhead on big databases.)'
PRINT N''
UPDATE dbo.##FO SET [-] = N'-', [==] = N'==', [=] = N'=', [+] = N'+'
RETURN (0)
GO
/****** Object: StoredProcedure [dbo].[sp_who3] Script Date: 04/03/2012
23:13:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_who3]
(
@SessionID int = NULL
)
AS
BEGIN
SELECT
SPID = er.session_id
,Status = ses.status
,[Login] = ses.login_name
,Host = ses.host_name
,BlkBy = er.blocking_session_id
,DBName = DB_Name(er.database_id)
,CommandType = er.command
,SQLStatement =
SUBSTRING
(
qt.text,
er.statement_start_offset/2,
(CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2
ELSE er.statement_end_offset
END - er.statement_start_offset)/2
)
,ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' +
OBJECT_NAME(qt.objectid, qt.dbid)
,ElapsedMS = er.total_elapsed_time
,CPUTime = er.cpu_time
,IOReads = er.logical_reads + er.reads
,IOWrites = er.writes
,LastWaitType = er.last_wait_type
,StartTime = er.start_time
,Protocol = con.net_transport
,transaction_isolation =
CASE ses.transaction_isolation_level
WHEN 0 THEN 'Unspecified'
WHEN 1 THEN 'Read Uncommitted'
WHEN 2 THEN 'Read Committed'
WHEN 3 THEN 'Repeatable'
WHEN 4 THEN 'Serializable'
WHEN 5 THEN 'Snapshot'
END
,ConnectionWrites = con.num_writes
,ConnectionReads = con.num_reads
,ClientAddress = con.client_net_address
,Authentication = con.auth_scheme
FROM sys.dm_exec_requests er
LEFT JOIN sys.dm_exec_sessions ses
ON ses.session_id = er.session_id
LEFT JOIN sys.dm_exec_connections con
ON con.session_id = ses.session_id
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) as qt
WHERE @SessionID IS NULL OR er.session_id = @SessionID
AND er.session_id > 50
ORDER BY
er.blocking_session_id DESC
,er.session_id
END
GO
/****** Object: StoredProcedure [dbo].[sp_WhoIsActive] Script Date: 04/03/2012
23:13:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[sp_WhoIsActive] AS SELECT 'stub version, to be replaced'
GO
/****** Object: StoredProcedure [dbo].[USP_ActiveTrans_OS_PRFCNR] Script Date:
04/03/2012 23:13:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
=====================PAGE NAME(CALLING)==============
=====================CREATED BY/DATE ================
SALMAN
27/05/2008
=====================================================
*/
--------------------------------------------------------------------
SET NOCOUNT ON
BEGIN
END
GO
/****** Object: StoredProcedure [dbo].[USP_AgentStatus] Script Date: 04/03/2012
23:13:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
========================PAGE NAME(CALLING)=====================
=========================CREATED BY/DATE ======================
*/
--------------------------------------------------------------------
SET NOCOUNT ON
GO
/****** Object: StoredProcedure [dbo].[USP_CPUUsage] Script Date: 04/03/2012
23:13:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
========================PAGE NAME(CALLING)=====================
=========================CREATED BY/DATE ======================
*/
--------------------------------------------------------------------
SET NOCOUNT ON
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]',
'int') AS SystemIdle,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]',
'int') AS SQLProcessUtilization,
TIMESTAMP
FROM ( SELECT TIMESTAMP, CONVERT(XML, record) AS record
FROM sys.dm_os_ring_buffers with(nolock)
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
AND record LIKE '% %') AS x
) AS y
ORDER BY record_id DESC
GO
/****** Object: StoredProcedure [dbo].[USP_DbHostCount] Script Date: 04/03/2012
23:13:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
as
--==========================PAGE NAME(CALLING)=======================
--==========================CREATED BY/DATE =========================
--Binod
--24/5/2008
--===================================================================
select hostname,count(spid) as "Total Srv Pro",db_name(qs.dbid) as
"DBName",@@servername as "Server"
from sys.sysprocesses as qs
GO
/****** Object: StoredProcedure [dbo].[USP_DiskStatus] Script Date: 04/03/2012
23:13:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
========================PAGE NAME(CALLING)=====================
=========================CREATED BY/DATE ======================
*/
--------------------------------------------------------------------
SET NOCOUNT ON
SET @cnt = 1
END
SELECT @@SERVERNAME SVRName,Drive,Total_Space AS Total_Space_GB,
(Free_space)/1024 Free_space_GB,GETDATE() Dt FROM @tbl_Drive
GO
/****** Object: StoredProcedure [dbo].[usp_get_db_files_near_maxsize] Script
Date: 04/03/2012 23:13:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_get_db_files_near_maxsize] (@nearMaxSizePct DECIMAL
(5,1) = 10.0)
AS
BEGIN
SET NOCOUNT ON
-- loop over all databases and collect the information from sysfiles
-- to the ALL_DB_Files tables using the sp_MsForEachDB system procedure
EXEC sp_MsForEachDB
@command1='use [$];Insert into ##ALL_DB_Files select db_name(), * from sysfiles',
@replacechar = '$'
ELSE 'Others'
END Reason
,ISNULL([desc],'') Errstring
,O.Dcupdtime
FROM SMCRegIDattribute MN WITH(NOLOCK)
INNER JOIN MC_GuidColoRel G WITH(Nolock) ON
MN.SSORegid=G.MCID AND mn.GUID=G.mcGUID and ResType=1
INNER JOIN MstRegidMCMCTRel REL WITH(nOLOCK) ON
REL.MCID=G.MCID AND REL.MCGUID=G.MCGUID
INNER JOIN MSTCOLODRV MD with(nolock) On
MD.Coloid=G.coloid
LEFT JOIN MC_MCTAscpOffsiteHealthCheck OCh
with(nolock) On OCh.MCTID=rel.MCTID
LEFT JOIN ( Select
O.MCTID,ISNULL(L.ServerGuid,O.ServerGuid) mcGUID,ISNULL(L.ErrorDesc,[Desc])
[Desc],O.Dcupdtime
From McAscpTfrOffsite O
with(nolock)
LEFT JOIN MCAscpTrfStatus L
with(nolock) ON L.MCTID=O.MCTID AND O.ServerGuid=L.ServerGuid
WHERE DCupdtime=(SELECT
ISNULL(O2.DT,O1.Dt)
FROM
( Select MCTID ,ServerGUID,max(dcupdtime) Dt
Group by MCTID,ServerGUID
)
O1
LEFT JOIN (
Select MCTID ,ServerGUID,max(dcupdtime) Dt
) t on T.MCTID=rel.MCTID
where
datediff(Mi,a.Dcupdtime,getdate())<=60
Group By G.Coloid
) A
Inner join
( select
G.Coloid,Errst,ratio,Count(Distinct a.MCTID) FNS
from McAscpTfrOffsite a
with(nolock)
Inner Join
MC_GuidColoRel G with(NoLock) On G.MCGUID=a.ServerGUID
Inner join
MC_AsperaTrfErrors Er with(Nolock) On charindex(errst,[desc])>0
where
datediff(Mi,a.Dcupdtime,getdate())<=60
Group By
G.Coloid,Errst,ratio
) B On A.Coloid=B.COLOID
) P On G.Coloid=P.Coloid And
T1.Errst=P.Errst
WHERE T.MCTID IS NULL
)X
LEFT JOIN MC_MCTColoTrfLookup TL With(Nolock) On
TL.MCGuid=X.ServerGuid AND TL.MCTID=X.MCTRegID
GO
/****** Object: StoredProcedure [dbo].[USP_MemoryUsage] Script Date: 04/03/2012
23:13:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
========================PAGE NAME(CALLING)=====================
=========================CREATED BY/DATE ======================
*/
--------------------------------------------------------------------
SET NOCOUNT ON
select top 1
x.value('(//TotalPhysicalMemory)[1]','int') as
[TotalPhysicalMemory],
x.value('(//AvailablePhysicalMemory)[1]','int')as
[AvailablePhysicalMemory],
x.value('(//Record/@time)[1]', 'bigint') as [TimeStamp]
from
(select cast(record as xml) as record
from sys.dm_os_ring_buffers WITH(NOLOCK)
where ring_buffer_type = N'RING_BUFFER_RESOURCE_MONITOR')
as r(x)
order by
[TimeStamp] desc
SET NOCOUNT ON
If @InTamID IS NULL
Begin
Insert Into @MemberList
(MemberID,BCurrency,BillingRequired)
Select MM.MemberID,MM.BCurrency,MM.BillingRequired
From GlobalConfig_Member MM With (NoLock)
Left Join @MemberList ML ON MM.MemberID=ML.MemberID
Where ML.MemberID Is Null AND
MM.BCurrency=IsNull(@InCurrency,MM.BCurrency)
AND
MM.BillingRequired=ISNULL(@InBillingRequired,MM.BillingRequired) AND MM.Memberid>@I
End
)A
Group By BCurrency,BillingRequired,WeekRange,ServiceId
)B
Left Join
(
Select BillingRequired,WeekRange,BCurrency,Min(FromDate)
FromDate,Min(ToDate) ToDate,SUM(C.Amount) Amount
FROM
(
Select BillingRequired,WeekRange,BCurrency,Min(FromDate)
FromDate,Min(ToDate) ToDate,SUM(a.Amount) Amount
From(
--Select Case When BillingRequired Is Null Then 0
Else BillingRequired End BillingRequired,GM.BCurrency,
Select GM.BillingRequired,GM.BCurrency,
DateAdd(d,0,DateDiff(d,0,Dateason))
DateAsOn,MS.Amount,WeekRange,MW.FromDate,MW.Todate
From AV_MemberPoolWise_Daily_Consol MS WITH(NOLOCK)
Inner Join @MemberList GM ON
MS.MEMBERID=GM.Memberid
Left Join MSO_Weekly_Slab MW
WITH(NOLOCK) On Day(MS.DateAson) BETWEEN MW.FromDate AND MW.Todate
Where MONTH(DateAsOn)=@InMonth AND
YEAR(DateAsOn)=@InYear
)A
Group By BCurrency,BillingRequired,WeekRange
UNION ALL
Select BillingRequired,WeekRange,BCurrency,Min(FromDate)
FromDate,Min(ToDate) ToDate,SUM(a.Amount) Amount
From(
Select GM.BillingRequired,GM.BCurrency,
--Select Case When BillingRequired Is Null Then 0
Else BillingRequired End BillingRequired,GM.BCurrency,
DateAdd(d,0,DateDiff(d,0,Dateason))
DateAsOn,MS.Amount,WeekRange,MW.FromDate,MW.Todate
From AV_MemberNonPoolWise_Daily_Consol MS
WITH(NOLOCK)
--Left Join GlobalConfig_Member
GM WITH(NOLOCK) ON MS.MEMBERID=GM.Memberid
Inner Join @MemberList GM ON
MS.MEMBERID=GM.Memberid
Left Join MSO_Weekly_Slab MW WITH(NOLOCK) On
Day(MS.DateAson) BETWEEN MW.FromDate AND MW.Todate
Where MONTH(DateAsOn)=@InMonth AND
YEAR(DateAsOn)=@InYear
)A
Group By BCurrency,BillingRequired,WeekRange
)C
Group By BCurrency,BillingRequired,WeekRange
)D on B.WeekRange=D.WeekRange AND B.BCurrency=D.BCurrency AND
B.BillingRequired=D.BillingRequired
Group By B.BCurrency,B.BillingRequired,B.WeekRange
ORDER BY B.BillingRequired,B.BCurrency,B.WeekRange
Option (Optimize for (@InMonth=Null,@InYear=Null))
SET NOCOUNT OFF
GO
/****** Object: StoredProcedure [dbo].[USP_ServiceDesk_ticket_Count_Report_Pr]
Script Date: 04/03/2012 23:13:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[USP_ServiceDesk_ticket_Count_Report_Pr]
@MemberId BIGINT=O,
@SiteCode varchar(30)=null,
@inFlag int,
@InFromDate DATETIME,
@InToDate DATETIME,
@Inmspname VARCHAR(255) = NULL,
@type varchar(100)='all',
@InFrom int=1,
@inTo int=300
/*
-----------------------------------------------------------
SET NOCOUNT ON
DECLARE @MyTableVar table(RegID bigint,TaskID bigint,StatusUpdatedOn datetime
,TaskSubject varchar(max),
Resource varchar(max),AssignTo varchar(max),GroupName varchar(max),Client
varchar(max),Location varchar(max),
taskdatetime datetime ,PRIORITY int,ASSIGNTOGROUP varchar(max),ASSIGNTOUSER
int,STATUS varchar(max))
if @inFlag=1
begin
IF @Inmspname IS NULL
BEGIN
END
select AM.mspname,RegID,COUNT(1)[count],GroupName,client,
open_noc=count(Case when AssignTo='NOC TEAM' and status not in(102,109)
then 1 end) ,
open_msp=count(Case when AssignTo='MSP' and status not in(102,109) then 1
end) ,
open_sd=count(Case when AssignTo='ServiceDesk' and status not in(102,109)
then 1 end) ,
close_noc_msp_sd=count(Case when AssignTo in('NOC TEAM','MSP','ServiceDesk')
and status in(102,109) then 1 end)
from jmgtTaskManagement TM WITH(NOLOCK)
select AM.mspname,RegID,COUNT(1)[count],GroupName,client,
open_noc=count(Case when AssignTo='NOC TEAM' and status not in(102,109)
then 1 end) ,
open_msp=count(Case when AssignTo='MSP' and status not in(102,109) then 1
end) ,
open_sd=count(Case when AssignTo='ServiceDesk' and status not in(102,109)
then 1 end) ,
close_noc_msp_sd=count(Case when AssignTo in('NOC TEAM','MSP','ServiceDesk')
and status in(102,109) then 1 end)
from jmgttaskclosed TM WITH(NOLOCK)
END
end
if @inFlag=3
begin
DECLARE @TMP111 TABLE(mspname VARCHAR(MAX),REGID INT ,[count]
INT,GroupName VARCHAR(MAX),client VARCHAR(MAX),
open_noc int,open_msp int,open_sd int,close_noc_msp_sd int)
-- select * from
-- (
-- SELECT AM.mspname, RM.SiteCode,
rm.SiteId,rm.MemberID,RM.ResourceName,ROW_NUMBER() OVER(ORDER BY ra.regid DESC) AS
RNUM
-- FROM RegIDAttribute RA WITH(NOLOCK)
-- inner JOIN RegMain RM WITH(NOLOCK) ON RM.Regid = RA.Regid
-- left JOIN AdhocMnMaster AM WITH(NOLOCK) ON RM.MemberCode = AM.mspname
-- AND RM.SiteCode = AM.ClientName
-- AND RM.SiteSubCode = AM.Locationname
-- where RA.Regtype = 'DPMA'
-- and RM.SiteCode =@SiteCode
-- and rm.MemberID =@MemberId
-- AND AM.mspname = @Inmspname
--)as B
-- where RNUM between @InFrom and @inTo
SELECT DISTINCT
a.mspname,A.MemberID,A.resourcename,a.SiteCode
FROM
(
SELECT TT.mspname,rm.MemberID,rm.resourcename,tt.client
SiteCode,sum(open_noc) open_noc,SUM(open_msp)open_msp,sum(open_sd) open_sd,
SUM(close_noc_msp_sd) close_noc_msp_sd,COUNT( RA.Regid)
DESKTOP_COUNT,sum([count]) TICKET_COUNT
FROM RegIDAttribute RA WITH(NOLOCK)
inner JOIN RegMain RM WITH(NOLOCK) ON RM.Regid = RA.Regid
end
if @inFlag=4
begin
if @type='all'
begin
select * from
(
SELECT statusName,TaskID,TaskSubject,Resource,A.AssignTo,Grp.GroupName AS
GRPNAME ,P.PriorityName
,convert(varchar,taskdatetime,113) Taskdatetime,duration,u.UserId
UserId,A.GroupName,A.Client,
A.Location,UserName,taskdatetime AS HRS,ROW_NUMBER() OVER(ORDER BY
taskdatetime DESC) AS RNUM
FROM
(
SELECT TT.TaskID,
TT.TaskSubject,TT.Resource,TT.AssignTo,TT.GroupName,TT.Client,TT.Location,
TT.PRIORITY,TT.ASSIGNTOGROUP,TT.ASSIGNTOUSER,TT.STATUS,TT.taskdatetime,
datediff(n, isnull(TT.StatusUpdatedOn, TT.taskdatetime) ,
getdate())duration
FROM RegIDAttribute RA WITH(NOLOCK)
left join @MyTableVar TT
on TT.regid=RA.regid
where RA.Regtype = 'DPMA'
) A
LEFT JOIN PRIORITYMASTER P WITH (NOLOCK) ON A.PRIORITY=P.PRIORITYID
INNER JOIN JMGTTSTATUS JMGTTSTATUS WITH (NOLOCK) ON
JMGTTSTATUS.STATUSID=A.STATUS
LEFT OUTER JOIN GROUPMASTER GRP WITH(NOLOCK) ON A.ASSIGNTOGROUP = GRP.GROUPID
if @type ='open_noc'
begin
select * from
(
SELECT statusName,TaskID,TaskSubject,Resource,A.AssignTo,Grp.GroupName AS
GRPNAME ,P.PriorityName
,convert(varchar,taskdatetime,113) Taskdatetime,duration,u.UserId
UserId,A.GroupName,A.Client,
A.Location,UserName,taskdatetime AS HRS,ROW_NUMBER() OVER(ORDER BY
taskdatetime DESC) AS RNUM
FROM
(
SELECT TT.TaskID,
TT.TaskSubject,TT.Resource,TT.AssignTo,TT.GroupName,TT.Client,TT.Location,
TT.PRIORITY,TT.ASSIGNTOGROUP,TT.ASSIGNTOUSER,TT.STATUS,TT.taskdatetime,
datediff(n, isnull(TT.StatusUpdatedOn, TT.taskdatetime) ,
getdate())duration
FROM RegIDAttribute RA WITH(NOLOCK)
left join @MyTableVar TT
on TT.regid=RA.regid
where RA.Regtype = 'DPMA'
) A
LEFT JOIN PRIORITYMASTER P WITH (NOLOCK) ON A.PRIORITY=P.PRIORITYID
INNER JOIN JMGTTSTATUS JMGTTSTATUS WITH (NOLOCK) ON
JMGTTSTATUS.STATUSID=A.STATUS
LEFT OUTER JOIN GROUPMASTER GRP WITH(NOLOCK) ON A.ASSIGNTOGROUP = GRP.GROUPID
begin
select * from
(
SELECT statusName,TaskID,TaskSubject,Resource,A.AssignTo,Grp.GroupName AS
GRPNAME ,P.PriorityName
,convert(varchar,taskdatetime,113) Taskdatetime,duration,u.UserId
UserId,A.GroupName,A.Client,
A.Location,UserName,taskdatetime AS HRS,ROW_NUMBER() OVER(ORDER BY
taskdatetime DESC) AS RNUM
FROM
(
SELECT TT.TaskID,
TT.TaskSubject,TT.Resource,TT.AssignTo,TT.GroupName,TT.Client,TT.Location,
TT.PRIORITY,TT.ASSIGNTOGROUP,TT.ASSIGNTOUSER,TT.STATUS,TT.taskdatetime,
datediff(n, isnull(TT.StatusUpdatedOn, TT.taskdatetime) ,
getdate())duration
FROM RegIDAttribute RA WITH(NOLOCK)
left join @MyTableVar TT
on TT.regid=RA.regid
where RA.Regtype = 'DPMA'
) A
LEFT JOIN PRIORITYMASTER P WITH (NOLOCK) ON A.PRIORITY=P.PRIORITYID
INNER JOIN JMGTTSTATUS JMGTTSTATUS WITH (NOLOCK) ON
JMGTTSTATUS.STATUSID=A.STATUS
LEFT OUTER JOIN GROUPMASTER GRP WITH(NOLOCK) ON A.ASSIGNTOGROUP = GRP.GROUPID
begin
select * from
(
SELECT statusName,TaskID,TaskSubject,Resource,A.AssignTo,Grp.GroupName AS
GRPNAME ,P.PriorityName
,convert(varchar,taskdatetime,113) Taskdatetime,duration,u.UserId
UserId,A.GroupName,A.Client,
A.Location,UserName,taskdatetime AS HRS,ROW_NUMBER() OVER(ORDER BY
taskdatetime DESC) AS RNUM
FROM
(
SELECT TT.TaskID,
TT.TaskSubject,TT.Resource,TT.AssignTo,TT.GroupName,TT.Client,TT.Location,
TT.PRIORITY,TT.ASSIGNTOGROUP,TT.ASSIGNTOUSER,TT.STATUS,TT.taskdatetime,
datediff(n, isnull(TT.StatusUpdatedOn, TT.taskdatetime) ,
getdate())duration
FROM RegIDAttribute RA WITH(NOLOCK)
left join @MyTableVar TT
on TT.regid=RA.regid
where RA.Regtype = 'DPMA'
) A
LEFT JOIN PRIORITYMASTER P WITH (NOLOCK) ON A.PRIORITY=P.PRIORITYID
INNER JOIN JMGTTSTATUS JMGTTSTATUS WITH (NOLOCK) ON
JMGTTSTATUS.STATUSID=A.STATUS
LEFT OUTER JOIN GROUPMASTER GRP WITH(NOLOCK) ON A.ASSIGNTOGROUP = GRP.GROUPID
begin
select * from
(
SELECT statusName,TaskID,TaskSubject,Resource,A.AssignTo,Grp.GroupName AS
GRPNAME ,P.PriorityName
,convert(varchar,taskdatetime,113) Taskdatetime,duration,u.UserId
UserId,A.GroupName,A.Client,
A.Location,UserName,taskdatetime AS HRS,ROW_NUMBER() OVER(ORDER BY
taskdatetime DESC) AS RNUM
FROM
(
SELECT TT.TaskID,
TT.TaskSubject,TT.Resource,TT.AssignTo,TT.GroupName,TT.Client,TT.Location,
TT.PRIORITY,TT.ASSIGNTOGROUP,TT.ASSIGNTOUSER,TT.STATUS,TT.taskdatetime,
datediff(n, isnull(TT.StatusUpdatedOn, TT.taskdatetime) ,
getdate())duration
FROM RegIDAttribute RA WITH(NOLOCK)
left join @MyTableVar TT
on TT.regid=RA.regid
where RA.Regtype = 'DPMA'
) A
LEFT JOIN PRIORITYMASTER P WITH (NOLOCK) ON A.PRIORITY=P.PRIORITYID
INNER JOIN JMGTTSTATUS JMGTTSTATUS WITH (NOLOCK) ON
JMGTTSTATUS.STATUSID=A.STATUS
LEFT OUTER JOIN GROUPMASTER GRP WITH(NOLOCK) ON A.ASSIGNTOGROUP = GRP.GROUPID
GO
/****** Object: StoredProcedure [dbo].[Usp_SrvTraceFlagStatus] Script Date:
04/03/2012 23:13:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
As
/*
--------------------------------------------------------------------
====================PURPOSE=========================
-- Description: Get the details of the following
ServerName
ServiceName
ProductVersion
SQLServer Language
Product Level
Edition
TraceFlag 1222 - Deadlock TraceFlag
TraceFlag 7806 - DAC enabled
TraceFlag 1118 - TempDb Trace
=====================INPUT/OUTPUT==========================
EXEC [Usp_SrvTraceFlagStatus]
=====================PAGE NAME(CALLING)==============
=====================ALTERD BY/DATE ================
RaKeSh Tiwarekar
09-Sep-2011
*/
CREATE TABLE #TraceFlagStatus
(
ID INT IDENTITY (1,1),
Trace_Flag INT ,
TraceStatus VARCHAR(5),
GlobalTraceStatus VARCHAR(5),
SessionTraceStatus VARCHAR(5)
)
GO
/****** Object: StoredProcedure [dbo].[Usp_SrvWiseJobInfo] Script Date:
04/03/2012 23:13:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[Usp_SrvWiseJobInfo]
As
/*
--------------------------------------------------------------------
====================PURPOSE=========================
-- Description: Get the details of the Job Schedule On Server
=====================INPUT/OUTPUT==========================
EXEC [Usp_SrvWiseJobInfo]
=====================PAGE NAME(CALLING)==============
=====================ALTERD BY/DATE ================
RaKeSh Tiwarekar
03-Sep-2011
*/
SELECT j.job_id,sched.schedule_id,j.name
,j.enabled,sched.enabled,NULL,sched.freq_type,sched.freq_interval,sched.freq_subday
_type,
sched.freq_subday_interval,sched.freq_relative_interval,sched.freq_recurrence_facto
r,sched.active_start_date,sched.active_end_date,
sched.active_start_time,sched.active_end_time,j.date_created FROM
msdb.dbo.sysjobs j inner join msdb.dbo.sysjobschedules s
ON j.job_id=s.job_id INNER JOIN msdb.dbo.sysschedules sched ON s.schedule_id
= sched.schedule_id
WHILE 1=1
BEGIN
SET @SCHEDULE = ''
IF (SELECT COUNT(*) FROM #SCHEDULES WHERE scheduled=1 and
schedule is null) = 0
BREAK
ELSE
BEGIN
SELECT
@job_id=job_id,@sched_id=sched_id,@freq_type=freq_type,@Freq_Interval=freq_interval
,@freq_subday_type=freq_subday_type,
@freq_subday_interval=freq_subday_interval,@freq_relative_interval=freq_relative_in
terval,@freq_recurrence_factor=freq_recurrence_factor,
@active_start_date = active_start_date,@start_time =CASE WHEN
LEFT(active_start_time, 2) IN (22, 23) AND len(active_start_time) = 6
THEN convert(varchar(2), left(active_start_time, 2) - 12) + ':' +
SUBSTRING(CAST(active_start_time AS CHAR),3, 2) + ' P.M'
WHEN active_start_time = 0
THEN '12:00 A.M.'
WHEN LEN(active_start_time) = 4
THEN '12:' + convert(varchar(2), left(active_start_time, 2) ) + ' A.M.'
WHEN LEN(active_start_time) = 3
THEN '12:0' + convert(varchar(2), left(active_start_time, 1) ) + '
A.M.'
WHEN LEN(active_start_time) = 2
THEN '12:00:' + convert(varchar(2), left(active_start_time, 2) ) + '
A.M.'
WHEN LEN(active_start_time) = 1
THEN '12:00:0' + convert(varchar(2), left(active_start_time, 2) ) + '
A.M.'
WHEN active_end_time = 0
THEN '12:00 A.M.'
WHEN LEN(active_end_time) = 4
THEN '12:' + convert(varchar(2), left(active_end_time, 2) ) + ' A.M.'
WHEN LEN(active_end_time) = 3
THEN '12:0' + convert(varchar(2), left(active_end_time, 1) ) + ' A.M.'
WHEN LEN(active_end_time) = 2
THEN '12:00:' + convert(varchar(2), left(active_end_time, 2) ) + '
A.M.'
WHEN LEN(active_end_time) = 1
THEN '12:00:0' + convert(varchar(2), left(active_end_time, 2) ) + '
A.M.'
ELSE
END
BEGIN
END
END
ELSE
BEGIN
IF @freq_type=4
BEGIN
SELECT @SCHEDULE = 'Occurs Every '+cast(@freq_interval as varchar(10))+' Day(s)'
END
IF @freq_type=8
BEGIN
SELECT @schedule_day=''
END
IF @freq_type=16
BEGIN
END
IF @freq_type=32
BEGIN
END
SELECT @SCHEDULE =
CASE @freq_subday_type
WHEN 1 THEN @SCHEDULE+', At '+@start_time
WHEN 2 THEN @SCHEDULE+', every '+cast(@freq_subday_interval as varchar(3))+'
Second(s) Between '+@start_time+' and '+@END_TIME
WHEN 4 THEN @SCHEDULE+', every '+cast(@freq_subday_interval as varchar(3))+'
Minute(s) Between '+@start_time+' and '+@END_TIME
WHEN 8 THEN @SCHEDULE+', every '+cast(@freq_subday_interval as varchar(3))+'
Hour(s) Between '+@start_time+' and '+@END_TIME
END
END
END
UPDATE #SCHEDULES
SET schedule=@SCHEDULE
WHERE job_id=@job_id
AND sched_id=@sched_Id
END
GO
/****** Object: StoredProcedure [dbo].[USP_SysMonitor] Script Date: 04/03/2012
23:13:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
exec USP_SysMonitor 4
*/
--------------------------------------------------------------------
As
SET NOCOUNT ON
If (@InType = 4)
BEGIN
DBCC SQLPERF(logspace)
END
Else If (@InType = 5)
Begin
select login_time,spid,cpu,text,hostname,cmd,status,waittime
from sys.sysprocesses as qs
CROSS APPLY sys.dm_exec_sql_text( qs.sql_handle) as st
where datediff(hh,login_time ,getdate())>2
order by login_time
End
Else If (@InType = 6)
begin
SELECT * FROM sys.dm_os_performance_counters with(nolock)
WHERE OBJECT_nAME='SQLServer:SQL Statistics'
AND COUNTER_NAME='Batch Requests/sec'
end
GO
/****** Object: StoredProcedure [dbo].[Wpost_MCTMCRelation_PRA] Script Date:
04/03/2012 23:13:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@InXml XML,
@OutStatus BIT OUTPUT,
@OUTXML VARCHAR(MAX) OUTPUT
AS
/*
declare @OutStatus bit,@OUTXML VARCHAR(MAX)
EXEC Wpost_MCTMCRelation_prA
'<wpmctmcagentinfo>
<mctid>5955</mctid>
<mctregid>1433879</mctregid>
<ftime>07/02/2011 19:49:12</ftime>
<mcinfo>
<mc mcname="WIN2K3-64_BIT" mcid="3718" mcguid= "12B0C41B-75C3-49BD-89EA-
04E67B89EC20" msoregid="1" fullyqname="win2k3-64_Bit" osname="Microsoft Windows
Server 2003" ostype="BIT64" />
<drdet>
<ldrive>
<inst><![CDATA[C]]></inst>
<total>20466</total>
<free>16050</free>
<used>4416</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[29874005-a743-11df-b7a5-806e6f6e6963]]></voln>
<isosdrive>1</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[E]]></inst>
<total>400</total>
<free>371</free>
<used>29</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[92204ac6-3674-4040-9673-1fca8cb0856e]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[F]]></inst>
<total>400</total>
<free>349</free>
<used>51</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[4ce08670-7693-441d-a919-4d527f3017de]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[G]]></inst>
<total>400</total>
<free>358</free>
<used>42</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[f796944b-8a35-438c-94bb-d50afa083e4b]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[H]]></inst>
<total>846</total>
<free>769</free>
<used>77</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[1f3b3d21-2099-4946-a454-dade126d7d00]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
</drdet>
</mcinfo>
<mcinfo>
<mc mcname="WIN2K3_64" mcid="5946" mcguid= "1A0EBC26-5A9E-4CA2-A93A-
A875CEC4CF2B" msoregid="" fullyqname="Win2K3_64" osname="Microsoft Windows Server
2003 R2" ostype="BIT64" />
<drdet>
<ldrive>
<inst><![CDATA[C]]></inst>
<total>15351</total>
<free>12569</free>
<used>2782</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[c03e3689-71f5-11e0-b561-806e6f6e6963]]></voln>
<isosdrive>1</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[D]]></inst>
<total>5120</total>
<free>5092</free>
<used>28</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[515c6fb7-a913-454b-a79e-6b9a4a85fc83]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[E]]></inst>
<total>5119</total>
<free>5091</free>
<used>28</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[c16ea5ed-310e-421a-8c5f-08a3bba38c1c]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[F]]></inst>
<total>5119</total>
<free>5091</free>
<used>28</used>
<dataoffset>2097152</dataoffset>
<voln><![CDATA[ca5bba56-3c20-4188-b6d4-0c3825caa328]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
</drdet>
</mcinfo>
<mcinfo>
<mc mcname="FARHAD-WIN7-64" mcid="5832" mcguid= "E27F6082-96D5-463B-BF68-
AF9732A5AD31" msoregid="1433878" fullyqname="Farhad-Win7-64" osname="Windows 7
Ultimate" ostype="BIT64" />
<drdet>
<ldrive>
<inst><![CDATA[C]]></inst>
<total>40860</total>
<free>21750</free>
<used>19110</used>
<dataoffset>4194304</dataoffset>
<voln><![CDATA[8487fbf0-bb6a-11df-8d4b-806e6f6e6963]]></voln>
<isosdrive>1</isosdrive>
</ldrive>
<ldrive>
<inst><![CDATA[D]]></inst>
<total>40960</total>
<free>32885</free>
<used>8075</used>
<dataoffset>4194304</dataoffset>
<voln><![CDATA[8487fbf1-bb6a-11df-8d4b-806e6f6e6963]]></voln>
<isosdrive>0</isosdrive>
</ldrive>
</drdet>
</mcinfo>
</wpmctmcagentinfo>' ,@OutStatus output ,@OUTXML OUTPUT
select @OutStatus,@OUTXML
=====================Webpost=========================
wpmctmcagentinfo
====================PURPOSE=========================
To insert and update md5str for Files
=====================OUTPUT==========================
Recordset
=====================CREATED BY/DATE ================
Mayank T 18/10/2010
*/
SET NOCOUNT ON
Begin try
DECLARE @idoc int
-----------------------
--INSERT INTO @TAB1
SELECT *
FROM OPENXML (@idoc, '/wpmctmcagentinfo',2)
with( mctid bigint '/wpmctmcagentinfo/@mctid'
,mctregid varchar(50) '/wpmctmcagentinfo/@mctregid'
,ftime datetime '/wpmctmcagentinfo/@ftime'
,mcname varchar(50)
'/wpmctmcagentinfo/mcinfo/mc/@mcname'
,mcid bigint
'/wpmctmcagentinfo/mcinfo/mc/@mcid'
,mcguid varchar(300)
'/wpmctmcagentinfo/mcinfo/mc/@mcguid'
,fullyqname varchar(300)
'/wpmctmcagentinfo/mcinfo/mc/@fullyqname'
,osname varchar(100)
'/wpmctmcagentinfo/mcinfo/mc/@osname'
,ostype varchar(300)
'/wpmctmcagentinfo/mcinfo/mc/@ostype'
,inst varchar(300)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@inst'
,total numeric(18,2)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@total'
,free numeric(18,2)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@free'
,used numeric(18,2)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@used'
,dataoffset varchar(50)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@dataoffset'
,voln varchar(300)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@voln'
,isosdrive char(4)
'/wpmctmcagentinfo/mcinfo/drdet/ldrive/@isosdrive'
)
-----------------------------------
--INSERT INTO @TAB2
--SELECT * FROM OPENXML (@idoc, '/wpmctmcagentinfo/mcinfo/mc',3)
--with(mcname varchar(50) ,mcid bigint ,mcguid varchar(300),fullyqname
varchar(300),osname varchar(100) ,ostype varchar(300))
---------------------------
--INSERT INTO @Tab3
--SELECT * FROM OPENXML (@idoc, '/wpmctmcagentinfo/mcinfo/drdet/ldrive',3)
--with(inst varchar(300) ,total numeric(18,2) ,free numeric(18,2) ,used
numeric(18,2) ,dataoffset varchar(50) ,voln varchar(300) ,isosdrive char(4))
-- DECLARE @tbl table
-- (
-- mctid bigint,mctregid bigint,mcname varchar(50),mcid
bigint,mcguid varchar(300),fullyqname varchar(1000),osname varchar(100),ostype
varchar(300),
-- inst varchar(300),total numeric(18,2),free numeric(18,2),used
numeric(18,2),dataoffset varchar(50), voln varchar(300) ,isosdrive char(4) , fdate
datetime
-- )
--
-- DECLARE @tblr table
-- (MCID bigint,MCGUID varchar(300),MCTName varchar(300),MCTID BIGINT)
--
-- INSERT INTO @tbl (mctid ,mctregid ,mcname ,mcid ,mcguid ,fullyqname
,osname ,ostype ,inst ,total, free ,used ,dataoffset ,voln, isosdrive ,fdate)
---- SELECT fileds.value('mctid[1]','bigint') ,
---- fileds.value('mctregid[1]','varchar(50)') ,
---- a.value('@mcname[1]','varchar(50)') ,
---- a.value('@mcid[1]','bigint') ,
---- a.value('@mcguid[1]','varchar(300)') ,
---- a.value('@fullyqname[1]','varchar(300)') ,
---- a.value('@osname[1]','varchar(100)') ,
---- a.value('@ostype[1]','varchar(300)') ,
---- b.value('inst[1]','varchar(300)') ,
---- b.value('total[1]','numeric(18,2)') ,
---- b.value('free[1]','numeric(18,2)') ,
---- b.value('used[1]','numeric(18,2)') ,
---- b.value('dataoffset[1]','varchar(50)') ,
---- b.value('voln[1]','varchar(300)') ,
---- b.value('isosdrive[1]','char(4)') ,
---- fileds.value('ftime[1]','datetime')
---- FROM @InXml.nodes('/wpmctmcagentinfo') as xmldata(fileds)--MstRegidMCRel
---- outer APPLY fileds.nodes('mcinfo/mc') as ta(a) --MC_RegidVolumeMonInfo
---- outer APPLY a.nodes('../drdet/ldrive') as tb(b)
--MC_RegidVolumeMonInfo
--
--select mctid ,mctregid ,mcname ,mcid ,mcguid ,fullyqname ,osname ,ostype
,inst ,total, free ,used ,dataoffset ,voln, isosdrive ,ftime
--from @tab1 cross apply @tab2 cross apply @tab3
EXEC sp_xml_removedocument @idoc
--
-- BEGIN TRANSACTION
--
---- UPDATE V SET DriveOffsiteBackup=0,MCTEnabled=0,UpDcdtime=GETDATE()
---- OUTPUT DELETED.MCID, DELETED.MCGuid, DELETED.VolumeLetter,
DELETED.VolumeLable, DELETED.vollocalguid, DELETED.SSODiskName,
DELETED.SSODiskGuid, DELETED.MCTEnabled, DELETED.FileSys, DELETED.OffsetValue,
DELETED.IQN, DELETED.TotalSize, DELETED.UsedSize,DELETED.FREE,
DELETED.PartitionType, DELETED.SystemVolume, DELETED.DriveOffsiteBackup,
DELETED.ISOSDrive, DELETED.IsMounted, DELETED.TargetIP, DELETED.DcDtime
,DELETED.UpDcdtime
---- INTO MC_RegidVolumeMonInfo_History (MCID, MCGuid, VolumeLetter,
VolumeLable, vollocalguid, SSODiskName, SSODiskGuid, MCTEnabled, FileSys,
OffsetValue, IQN, TotalSize, UsedSize,FREE, PartitionType, SystemVolume,
DriveOffsiteBackup, ISOSDrive, IsMounted, TargetIP, DcDtime,UpDcdtime)
----
---- FROM
---- @tbl T
---- inner join MC_RegidVolumeMonInfo V WITH(NOLOCK) ON
V.MCID=T.MCID
---- INNER JOIN MstRegidMCMCTRel R WITH(NOLOCk) ON R.MCID=T.MCID
AND R.MCTID<>T.MCTID
--
--
-- --------------mc relation
--
---- delete M
---- OUTPUT DELETED.MCID, DELETED.SSORegid, DELETED.Status,
DELETED.MCGUID, DELETED.SSOCloudIP, DELETED.SSOCloudUser, DELETED.ConfiguredVM,
DELETED.ConfiguredVMGuid, DELETED.DcDtime, DELETED.ConfiguredPMName,
DELETED.CoonfiguredPMGuid, DELETED.MCOSName, DELETED.MCOSVersion,
DELETED.IPAddress, DELETED.MCNAME, DELETED.MnDTime, DELETED.UpDDcDtime,
DELETED.IsMCManaged, DELETED.RecoverType, DELETED.ColoRepliType,
DELETED.FullyQName ,DELETED.OSType
---- INTO MstRegidMCRel_History( MCID, SSORegid, Status, MCGUID,
SSOCloudIP, SSOCloudUser, ConfiguredVM, ConfiguredVMGuid, DcDtime,
ConfiguredPMName, CoonfiguredPMGuid, MCOSName, MCOSVersion, IPAddress, MCNAME,
MnDTime, UpDDcDtime, IsMCManaged, RecoverType, ColoRepliType, FullyQName,OSType)
---- FROM
---- MstRegidMCRel AS M WITH(NOLOCK)
---- INNER JOIN MstRegidMCMCTRel R WITH(NOLOCK) ON R.MCID=M.MCID
---- INNER JOIN @tbl AS TT ON TT.MCTID=R.MCTID
---- left JOIN @tbl T ON T.MCID = M.MCID
----
---- WHERE T.MCID IS NULL
--
--
--
-- --MstRegidMCMCTRel
---- DELETE M
---- OUTPUT DELETED.MCID, DELETED.MCGUID,
DELETED.MCTID,DELETED.MCTRegid, DELETED.ExcludeTTMDF, DELETED.ExcludeITMDF,
DELETED.BWUsageLimit, DELETED.BWUsageMin, DELETED.DcDtime,
DELETED.UpDDcDtime,DELETED.MnDtime
---- INTO MstRegidMCMCTRel_History(MCID, MCGUID, MCTID,MCTRegid,
ExcludeTTMDF, ExcludeITMDF, BWUsageLimit, BWUsageMin, DcDtime, UpDDcDtime,MnDtime)
---- FROM MstRegidMCMCTRel AS M WITH(NOLOCK)
---- LEFT JOIN @tbl AS T ON M.MCGUID = T.MCGUID AND M.MCID = T.MCID
AND M.MCTID = T.MCTID
---- INNER JOIN @tbl AS TT ON TT.MCTID=M.MCTID
---- WHERE T.MCID IS NULL
--
--
-- UPDATE M
-- SET UpDDcDtime = GETDATE(),MCTRegid=T.mctregid
--,M.MCTID=T.MCTID
-- OUTPUT DELETED.MCID, DELETED.MCGUID, DELETED.MCTID,
DELETED.ExcludeTTMDF, DELETED.ExcludeITMDF, DELETED.BWUsageLimit,
DELETED.BWUsageMin, DELETED.DcDtime, DELETED.UpDDcDtime
-- INTO MstRegidMCMCTRel_History(MCID, MCGUID, MCTID, ExcludeTTMDF,
ExcludeITMDF, BWUsageLimit, BWUsageMin, DcDtime, UpDDcDtime)
-- FROM MstRegidMCMCTRel AS M WITH(NOLOCK)
-- INNER JOIN @tbl AS T ON M.MCGUID = T.MCGUID AND M.MCID = T.MCID
AND M.MCTID = T.MCTID
--
------------------
-- INSERT INTO @tblr(MCID,MCGUID,MCTName,MCTID)
-- SELECT distinct T.mcid,T.mcguid,ResourceName ,M.MCTID
-- FROM @tbl AS T
-- INNER JOIN MstRegidMCMCTRel AS M WITH(NOLOCK) ON M.MCGUID =
T.MCGUID AND M.MCID = T.MCID AND M.MCTID <> T.MCTID
-- left JOIN SSOREGMAIN D WITH(NOLOCK) ON D.SSOREGID=M.MCTID
--
---------------
--
--
-- INSERT INTO
MstRegidMCMCTRel(MCID,MCGUID,MCTID,MCTRegid,UpDDcDtime,MNDTIME)
-- SELECT distinct T.mcid,T.mcguid,T.mctid,T.mctregid,GETDATE() ,FDATE
-- FROM @tbl AS T
-- LEFT JOIN MstRegidMCMCTRel AS M WITH(NOLOCK) ON M.MCGUID =
T.MCGUID AND M.MCID = T.MCID --AND M.MCTID = T.MCTID
-- where M.MCID IS NULL
--
--
-- --MC_RegidVolumeMonInfo
---- UPDATE VOL
---- SET
---- VOL.IsRemoteMirror =0
---- OUTPUT DELETED.MCID, DELETED.MCGuid, DELETED.VolumeLetter,
DELETED.VolumeLable, DELETED.vollocalguid, DELETED.SSODiskName,
DELETED.SSODiskGuid, DELETED.MCTEnabled, DELETED.FileSys, DELETED.OffsetValue,
DELETED.IQN, DELETED.TotalSize, DELETED.UsedSize,DELETED.FREE,
DELETED.PartitionType, DELETED.SystemVolume, DELETED.DriveOffsiteBackup,
DELETED.ISOSDrive, DELETED.IsMounted, DELETED.TargetIP,
DELETED.DcDtime,DELETED.UpDcdtime ,deleted.IsRemoteMirror,deleted.IsLocalMirror
---- INTO MC_RegidVolumeMonInfo_History (MCID, MCGuid, VolumeLetter,
VolumeLable, vollocalguid, SSODiskName, SSODiskGuid, MCTEnabled, FileSys,
OffsetValue, IQN, TotalSize, UsedSize, FREE,PartitionType, SystemVolume,
DriveOffsiteBackup, ISOSDrive, IsMounted,
---- TargetIP,
DcDtime,UpDcdtime,IsRemoteMirror,IsLocalMirror)
---- FROM MC_RegidVolumeMonInfo AS VOL
---- INNER JOIN @tbl T ON VOL.MCID= T.mcid
---- LEFT JOIN @tbl E ON VOL.MCID= E.mcid and VOL.VolumeLetter = E.inst
---- WHERE E.inst IS NULL
----
----
---- UPDATE VOL
---- SET
---- VOL.RemoteMirror
=null,RemoteFlush=null,PrevRemoteFlush=null,LastRemoteFlushChange=null,RemoteBaseSt
atus=null
----
---- FROM MC_QALookup AS VOL
---- INNER JOIN @tbl T ON VOL.MCID= T.mcid
---- LEFT JOIN @tbl E ON VOL.MCID= E.mcid and VOL.VolumeName = E.inst
---- WHERE E.inst IS NULL
----
-- UPDATE VOL
-- SET
-- VOL.ISOSDrive=Case when ISNULL(T.ISOSDrive,'')='' then
VOL.ISOSDrive ELSE T.ISOSDrive END,
-- VOL.UpDcdtime = getdate()
-- OUTPUT DELETED.MCID, DELETED.MCGuid, DELETED.VolumeLetter,
DELETED.VolumeLable, DELETED.vollocalguid, DELETED.SSODiskName,
DELETED.SSODiskGuid, DELETED.MCTEnabled, DELETED.FileSys, DELETED.OffsetValue,
DELETED.IQN, DELETED.TotalSize, DELETED.UsedSize,DELETED.FREE,
DELETED.PartitionType, DELETED.SystemVolume, DELETED.DriveOffsiteBackup,
DELETED.ISOSDrive, DELETED.IsMounted, DELETED.TargetIP, DELETED.DcDtime
,DELETED.UpDcdtime,deleted.IsRemoteMirror,deleted.IsLocalMirror
-- INTO MC_RegidVolumeMonInfo_History (MCID, MCGuid, VolumeLetter,
VolumeLable, vollocalguid, SSODiskName, SSODiskGuid, MCTEnabled, FileSys,
OffsetValue, IQN, TotalSize, UsedSize,FREE, PartitionType, SystemVolume,
DriveOffsiteBackup, ISOSDrive, IsMounted, TargetIP,
DcDtime,UpDcdtime,IsRemoteMirror,IsLocalMirror)
--
-- FROM MC_RegidVolumeMonInfo VOL WITH(NOLOCK)
-- INNER JOIN @tbl T ON VOL.MCID= T.mcid and VOL.VolumeLetter =
T.inst AND VOL.MCGuid=T.MCGuid
----
---- INSERT INTO MC_RegidVolumeMonInfo(IsRemoteMirror,MCID,
MCGuid,VolumeLetter,VolumeLable,TotalSize,UsedSize,OffsetValue,Free,UpDcdtime,vollo
calguid )
---- SELECT DISTINCT 1,T.mcid,T.mcguid,T.inst,T.voln,T.total,T.used,
T.dataoffset,T.free,getdate(),voln
---- FROM @tbl T
---- LEFT JOIN MC_RegidVolumeMonInfo VOL WITH(NOLOCK) ON VOL.MCID=
T.MCID
---- and VOL.VolumeLetter = T.inst AND
VOL.MCGuid=T.MCGuid
---- WHERE VOL.MCID IS NULL
--
-- --MstRegidMCRel
--
--
--
--
-- UPDATE M SET
-- M.MCNAME =Case when ISNULL(M.MCNAME,'')='' then T.mcname ELSE
M.MCNAME END,UpDDcDtime = GETDATE(),MCGUID=t.mcguid,M.FullyQName =Case when
isnull(M.FullyQName,'')='' then T.fullyqname else M.FullyQName end,
-- M.MCOSName = T.osname ,M.OSType = T.ostype
-- OUTPUT DELETED.MCID, DELETED.SSORegid, DELETED.Status,
DELETED.MCGUID, DELETED.SSOCloudIP, DELETED.SSOCloudUser, DELETED.ConfiguredVM,
DELETED.ConfiguredVMGuid, DELETED.DcDtime, DELETED.ConfiguredPMName,
DELETED.CoonfiguredPMGuid, DELETED.MCOSName, DELETED.MCOSVersion,
DELETED.IPAddress, DELETED.MCNAME, DELETED.MnDTime, DELETED.UpDDcDtime,
DELETED.IsMCManaged, DELETED.RecoverType, DELETED.ColoRepliType,
DELETED.FullyQName ,DELETED.OSType
-- INTO MstRegidMCRel_History( MCID, SSORegid, Status, MCGUID,
SSOCloudIP, SSOCloudUser, ConfiguredVM, ConfiguredVMGuid, DcDtime,
ConfiguredPMName, CoonfiguredPMGuid, MCOSName, MCOSVersion, IPAddress, MCNAME,
MnDTime, UpDDcDtime, IsMCManaged, RecoverType, ColoRepliType, FullyQName,OSType)
-- FROM
-- MstRegidMCRel AS M WITH(NOLOCK)
-- INNER JOIN @tbl T ON T.MCID = M.MCID
--
-- INSERT INTO
MstRegidMCRel(MCID,MCNAME,UpDDcDtime,MCGUID,fullyqname,MCOSName,OSType)
-- SELECT distinct T.MCID
,T.mcname,GETDATE(),T.MCGUID,t.fullyqname,T.osname ,T.ostype
-- FROM
-- @tbl T
-- LEFT JOIN MstRegidMCRel AS M WITH(NOLOCK) ON T.MCID = M.MCID
-- WHERE M.MCID IS NULL
----
---- INSERT INTO MC_QALookup (MCID,MCGUID,VolGUID,updcdtime,VolumeName)
---- SELECT distinct T.MCID,T.MCGUID,t.voln,getdate(),T.inst
---- FROM @tbl T
---- LEFT JOIN MC_QALookup as L WITH(NOLOCK) ON l.MCID= T.MCID
---- and l.VolumeName = T.inst AND
l.MCGuid=T.MCGuid
---- WHERE L.VolumeName IS NULL
--
--
-- --MC_RegidDISkInfo
---- INSERT INTO MC_RegidDISkInfo( MCdtime,MCID, MCGuid, VolumeLetter,
TotalSize, UsedSize,ISOSDrive)
---- SELECT DISTINCT fdate,
T.MCID,T.MCGUID,T.inst,T.total,T.used,T.isosdrive
---- FROM @tbl T
---- LEFT JOIN MC_RegidDISkInfo VOL WITH(NOLOCK) ON VOL.MCID= T.MCID
AND VOL.MCGuid = T.MCGUID and VOL.VolumeLetter = T.inst
---- WHERE VOL.MCID is null
----
---- update VOL set
---- MCdtime = T.fdate,
---- TotalSize = T.total ,
---- UsedSize = T.used,
---- ISOSDrive = T.isosdrive
---- FROM @tbl T
---- INNER JOIN MC_RegidDISkInfo VOL WITH(NOLOCK) ON VOL.MCID=
T.MCID AND VOL.MCGuid = T.MCGUID and VOL.VolumeLetter = T.inst
----
-- if exists(select top 1 mctid from @tblr)
-- begin
-- set @outxml='<mcrelation>'
-- SET @OUTXML=@OUTXML+(SELECT MCID as mcid,MCGUID as
mcguid,MCTNAME AS mctname,mctid
-- FROM @tblr AS mcrelation FOR XML AUTO)
-- set @outxml=@outxml + '</mcrelation>'
-- end
-- ELSE
-- BEGIN
-- set @outxml='<mcrelation>
-- </mcrelation>'
-- END
-- COMMIT TRANSACTION
-- set @OutStatus = 1
end try
begin catch
select error_message()
ROLLBACK TRANSACTION
set @OutStatus = 0
end catch