Wednesday, 16 February 2022

After saving Trace file to table , query which will help what query is taking what time and easy to find query taking longest time to run/return result

 SELECT MAX(ObjectName),

    ApplicationName,
    SPID,
    EventClass,
    MIN(RowNumber),
    MAX(RowNumber),
    Min(StartTime),
    MAX(EndTime),
    Convert(VARCHAR(max),TextData) TextData,
    COUNT(1) Count,
    SUM(Duration)/1000000.0 Sum,
    avg(Duration)/1000000.0 Avg,
    min(Duration)/1000000.0 Min,
    max(Duration)/1000000.0 Max,
    AVG(Reads) Reads,     AVG(RowCounts)   RowCounts
FROM Related  WITH (NOLOCK)
WHERE 1=1
AND EventClass <> 15
-- AND Duration > 1000
GROUP BY Convert(VARCHAR(max),TextData),EventClass, SPID, ApplicationName
 --ORDER BY AVG(RowCounts) DESC
ORDER BY SUM(Duration) desc

Monday, 31 January 2022

Query run against all DBs for any customer that has PaperSave for Dynamics GP, Financial Edge, Dynamics SL, Intacct, and Dynamics 365 Business Central that also have the auto entry module installed.

 Query run against all DBs for any customer that has PaperSave for Dynamics GP, Financial Edge, Dynamics SL, Intacct, and Dynamics 365 Business Central that also have the auto entry module installed.

 

Here is the query I have created which will run against all DBs for any customer that has PaperSave for Dynamics GP, Financial Edge, Dynamics SL, Intacct, and Dynamics 365 Business Central that also have the auto entry module installed.

 

use master

DECLARE @db_name nvarchar(max)

DECLARE @string nvarchar(max)

DECLARE @ID INT

DECLARE @sqlCommand NVARCHAR(4000)

if object_ID(N'tempdb..#report') is not null

begin

drop table #report

end

CREATE TABLE #report (Teanant nvarchar(max),HostaApplicationName nvarchar(max),CompnayName nvarchar(max))

DECLARE c_db_names CURSOR FOR

SELECT name FROM sys.databases 

--WHERE name IN ('PaperSaveSP11')

WHERE name not IN('master','model','msdb','tempdb','DBATools','PaperSaveContentSearchTest','PaperSaveGrantEdge','PaperSaveInvoiceReport','PaperSavemylesvcrm','PaperSaveTenants','papersave2') order by name --might need to exclude more dbs

OPEN c_db_names

FETCH c_db_names INTO @db_name WHILE @@Fetch_Status = 0

BEGIN

SET @sqlCommand = 'USE '+@db_name+' ;  select @ID=count(ID) from config where ConfigName =''Auto Entry enabled'' and ConfigValue=''yes'''

EXEC sp_executesql @sqlCommand, N'@ID INT OUTPUT',@ID = @ID OUTPUT

--print @ID

if (@ID>0)

begin

EXEC(' INSERT INTO #report(Teanant,HostaApplicationName,CompnayName) select ''' + @db_name + ''',h.Name,c.CompanyName from ' + @db_name + '..hostapplication h inner join ' + @db_name + '..Company c on h.ID=c.HostApplication_ID where Name = ''Dynamics GP'' or Name = ''Blackbaud''''s The Financial Edge'' or Name =''Microsoft Dynamics SL'' or Name = ''Dynamics 365 Business Central'' or Name = ''Intacct''')

--print @string

end

FETCH NEXT FROM c_db_names INTO @db_name

END

CLOSE c_db_names

DEALLOCATE c_db_names

SELECT * FROM #report


Thursday, 8 October 2015

get Element value from xml

declare @Text xml ;
set @Text= '<?xml version="1.0" encoding="utf-8"?>
<Project>

    <System_Record_ID><![CDATA[35]]></System_Record_ID>
      <Project_ID><![CDATA[1100]]></Project_ID>
 
</Project>'

;with t as (select @Text [xmlcolumn])
--select * from t
SELECT  x.a.value('(System_Record_ID)[1]','nvarchar(max)') as [System_Record_ID]
,       x.a.value('(Project_ID)[1]','nvarchar(max)') as [Project_ID]
FROM   t
cross apply

t.xmlcolumn.nodes('//Project') x(a)

Wednesday, 30 September 2015

substring , reverse and charindex


declare @s varchar(200);

set @s='F9ADD13F-B055-497B-83CB-ECF6CEE29C0E;163;AAA Concrete;Payment;10.00;Cash;2015-07-23;(Payment) 10.00 Cash - AAA Concrete;24;'
declare @a varchar(200);
declare @b varchar(200);
declare @c varchar(200);
declare @d varchar(200);
declare @e varchar(200);
declare @f varchar(200);
declare @g varchar(200);
declare @h varchar(200);


set @a=       SUBSTRING(@s, charindex(';', @s)+1, len(@s) )

--select @a;

set @b=   SUBSTRING(@a,CHARINDEX(';',@a)+1 ,len(@a))

set @c=   SUBSTRING(@b,CHARINDEX(';',@b)+1 ,len(@b))

set @d=   SUBSTRING(@c,CHARINDEX(';',@c)+1 ,len(@c))

--select @d;
set @e=SUBSTRING(@d,0,CHARINDEX(';',@d) )

select @e;

set @f= SUBSTRING(REVERSE(@s),2,len(@s))



set @g= REVERSE(SUBSTRING(@f, 1, charindex(';', @f)-1))


select @g;




Tuesday, 11 August 2015

Windows basic tools which are very useful while troubleshooting :

Windows basic tools which are very useful while troubleshooting :

-> Event viewer:

Event viewer is the important tool where you can find all logs of windows as well as about all your applications. It will very useful to find cause of issues. like let say , application programmers generally writes all event logs in code. so whenever your application stops working or give some weird issue that time you can find log information in eventlogs/event viewer

If you are working with client/server troubleshooting than you can find logs on server as well if issues is from server side. you can open event viewer from control panel->system and security -> Administrative tools-> Event viewer

short cut to open that : open Run (you can open that by pressing Windows+R button) and type eventvwr and event viewer will open.

Below is look of that:



Alos more information you can get from msdn blog:

http://windows.microsoft.com/en-in/windows/what-information-event-logs-event-viewer#1TC=windows-7



-> Services in Windows:

 this will be very useful during your troubleshooting , whatever services is running within your system you will find here:

to open that: Open Control Panel -> System and Security -> Administrative Tools -> Services

Shortcut to open that:

type windows+R and type services.msc and services will open

How it looks like:



from here you can start service , stop service , by right click and select properties you can setup various things like how you want to run your service like automatic, manual etc.


you can also find more information from below msdn blog:

http://www.7tutorials.com/what-are-windows-services-what-they-do-how-manage-them

Registry Editor:

Registry editor is tool from where you can find registry of you system , your applications etc. Generally application programmer/developer used to write few values in registry like installation information , few config values and during troubleshooting you may need to check/update these values . Even some time you need to check system registry , microsoft applications registry etc

that time you will need to open resgistry editor:

How to open that:
Type windows +R and  type "regedit"   (without quote) and it will open.

Here is msdn article:
http://windows.microsoft.com/en-in/windows/what-is-registry-editor#1TC=windows-7

Here is its look:



Fire Wall:

Some times you need to check firewall settings , mainly during troubleshooting of client server programs , that time you will need to open port from server and client which your application is using . for that you will need to open firewall

How to open that:

type windows +R and type "firewall.cpl" (without quote) and it will open.

Below is look of firewall:




More from msdn:
http://windows.microsoft.com/en-in/windows/what-is-firewall#1TC=windows-7




Wednesday, 29 July 2015

Basic Tips of SQL Scripts : Need to know while troubleshooting

Good SQL knowledge is very necessary when you do technical troubleshooting. In this part you must have knowledge about basic sql like insert, update , delete ,create, drop , truncate.

->Also you must have knowledge about few keywords like "between", "top " , "order by" , "group by ", "distinct", "Replace",

->Also learn Join , mainly inner join will be very useful. Trigger, stored procedure will be also useful to troubleshoot deeply. 

->Trigger will be helpful when table's data are being updated and you need to track all data information , you can create new table and track records in that table. see below trigger example,

->Cursor knowledge is required when you will need to update multiple rows dynamically.

-> Also try to learn SQL Server Profiler , it will be very useful when you want to track sql scripts

You can follow below article for this:

http://www.codeproject.com/Articles/21371/SQL-Server-Profiler-Step-by-Step
See below sample scripts to get basic idea of inner join , cursor, trigger:

Inner Join Sample


select h.ID,m.ID as moduleid,dt.ID as DocTypeId,dt.Name as docTypeName,tt.Name as transactionTypeNAME,tt.ID AS tRANSACTIONTYPEID,dt.* from DocumentType dt
inner join TransactionType tt on dt.TransactionType_ID =tt.ID
inner join Module m on tt.Module_ID=m.ID
inner join HostApplication h on m.HostApplication_ID=h.ID  order by dt.Name desc



Cursor Sample:

1) 
DECLARE @i int
DECLARE @HaldID bigint
DECLARE @HaldParentID varchar(250)
DECLARE @UpdateHALD CURSOR




--BBCRM - Prospect - 442
PRINT 'BBCRM - Prospect  - 442'
SET @i=0;
SET @UpdateHALD = CURSOR FOR
SELECT ID,ParentID FROM PaperSave..HostApplicationLocalData WITH (NOLOCK)
 WHERE TransactionType_ID=442 AND ID IN (SELECT HostApplicationLocalData_ID FROM Document) and len(HostDataValues)<40
OPEN @UpdateHALD
FETCH NEXT
FROM @UpdateHALD INTO @HaldID,@HaldParentID
WHILE @@FETCH_STATUS = 0
BEGIN

WITH GetHALD AS (SELECT UPPER(CONVERT(varchar(100),PROS.ID)) AS [ParentID] ,UPPER(CONVERT(varchar(100),PROS.ID)) AS [Prospect ID] ,C.NAME AS [Constituent],c.LOOKUPID As [Lookup ID],ISNULL((select NAME From Shelby..CONSTITUENT Where ID=PROS.PROSPECTMANAGERFUNDRAISERID),'')AS [Prospect Manager],convert(date,isnull(PROS.PROSPECTMANAGERSTARTDATE,'1999-01-01')) AS [Start Date],ISNULL(AD.CITY,'') AS  [City],ISNULL(STATE.DESCRIPTION,'') As [State],ISNULL(Ad.POSTCODE,'') As [Zip] FROM Shelby..PROSPECT PROS LEFT JOIN Shelby..CONSTITUENT C on PROS.ID = C.ID  LEFT JOIN (select  CONSTITUENTID, CITY, POSTCODE,ADDRESSBLOCK,Convert(varchar(100),STATEID) as STATEID From Shelby..ADDRESS where ISPRIMARY = 1) AD ON c.ID = AD.CONSTITUENTID  LEFT JOIN Shelby..STATE ON STATE.ID = AD.STATEID WHERE UPPER(CONVERT(varchar(100),PROS.ID))=@HaldParentID)

UPDATE PaperSave..HostApplicationLocalData
SET HostData='<?xml version="1.0" encoding="utf-8"?><Prospect><Prospect_ID><![CDATA[' + (SELECT ISNULL([Prospect ID],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Prospect_ID><Constituent><![CDATA[' + (SELECT ISNULL([Constituent],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Constituent><Lookup_ID><![CDATA[' + (SELECT ISNULL([Lookup ID],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Lookup_ID><Prospect_Manager><![CDATA[' + (SELECT ISNULL([Prospect Manager],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Prospect_Manager><Start_Date><![CDATA[' + (SELECT CONVERT(varchar,[Start Date]) FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Start_Date><City><![CDATA[' + (SELECT ISNULL([City],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></City><State><![CDATA[' + (SELECT ISNULL([State],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></State><Zip><![CDATA[' + (SELECT ISNULL([Zip],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ']]></Zip></Prospect>'
,
HostDataValues= (SELECT ISNULL([Prospect ID],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([Constituent],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([Lookup ID],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([Prospect Manager],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT CONVERT(varchar,[Start Date]) FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([City],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([State],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';' + (SELECT ISNULL([Zip],'') FROM GetHALD WHERE ParentID=HostApplicationLocalData.ParentID) + ';'

WHERE TransactionType_ID=442 AND ID=@HaldID
SET @i=@i+1;
PRINT CONVERT(varchar,@i) + ' Updated'
FETCH NEXT
FROM @UpdateHALD INTO @HaldID,@HaldParentID
END
CLOSE @UpdateHALD

DEALLOCATE @UpdateHALD

2)


use PaperSave
DECLARE @i int
DECLARE @HALD_ID bigint
DECLARE @HostDataValues varchar(250)
DECLARE @UpdateParentID CURSOR
declare @s varchar(200);
declare @a varchar(200);
declare @b varchar(200);
declare @c varchar(200);
declare @d varchar(200);
declare @e varchar(200);
declare @f varchar(200);
declare @g varchar(200);
declare @h varchar(200);
declare @Parentid varchar(200);

SET @UpdateParentID = CURSOR FOR
select ID , HostDataValues from HostApplicationLocalData where TransactionType_ID=340  and  Id=10132

SET @i=0;
OPEN @UpdateParentID
FETCH NEXT
FROM @UpdateParentID INTO @HALD_ID,@HostDataValues
WHILE @@FETCH_STATUS = 0
BEGIN

--select parentid  from HostApplicationLocalData where TransactionType_ID=340  and  Id=10132
-- F9ADD13F-B055-497B-83CB-ECF6CEE29C0E;163;AAA Concrete;Payment;10.00;Cash;2015-07-23;(Payment) 10.00 Cash - AAA Concrete;24;
set @s=@HostDataValues;
set @a=       SUBSTRING(@s, charindex(';', @s)+1, len(@s) )
--select @a;
set @b=   SUBSTRING(@a,CHARINDEX(';',@a)+1 ,len(@a))
set @c=   SUBSTRING(@b,CHARINDEX(';',@b)+1 ,len(@b))
set @d=   SUBSTRING(@c,CHARINDEX(';',@c)+1 ,len(@c))
--select @d;
set @e=SUBSTRING(@d,0,CHARINDEX(';',@d) )
select @e;
set @f= SUBSTRING(REVERSE(@s),2,len(@s))
set @g= REVERSE(SUBSTRING(@f, 1, charindex(';', @f)-1))
select @g;


set @Parentid= (select ID from BBInfinity..revenue where batchnumber =@g and amount=@e);


update HostApplicationLocalData set ParentID=@Parentid where id=@HALD_ID

-- get PO number from document id

-- store below query result in one variable


FETCH NEXT
FROM @UpdateParentID INTO  @HALD_ID,@HostDataValues
END
CLOSE @UpdateParentID

DEALLOCATE @UpdateParentID

Trigger Sample




USE [BBInfinity]
GO

/****** Object:  Table [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger]    Script Date: 7/2/2015 12:23:33 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger](
[ID] [uniqueidentifier] NOT NULL,
[COMMITEDBATCHREVENUEID] [nvarchar](50) NOT NULL,
[ADDEDBYID] [uniqueidentifier] NOT NULL,
[CHANGEDBYID] [uniqueidentifier] NOT NULL,
[DATEADDED] [datetime] NOT NULL,
[DATECHANGED] [datetime] NOT NULL,
[TS] [timestamp] NOT NULL,
[TSLONG] [bigint] NULL,
[Status] [nvarchar](50) NULL,
[Date] [datetime] NULL CONSTRAINT [DF_USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger_Date]  DEFAULT (getdate())
) ON [DEFGROUP]

GO


Insert Trigger: 


/****** Object:  Trigger [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_Insert_Logs]    Script Date: 7/2/2015 12:19:26 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:                <Author,,Name>
-- Create date: <Create Date,,>
-- Description:        <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_Insert_Logs]
   ON [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING]
   For Insert
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;



INSERT INTO [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger]
           ([ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG]
           ,[Status])
   
Select  [ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG],'Inserted' from inserted;

END

GO


 Delete Trigger: 

USE [BBInfinity]
GO

/****** Object:  Trigger [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_update_Logs]    Script Date: 7/2/2015 12:20:07 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:                <Author,,Name>
-- Create date: <Create Date,,>
-- Description:        <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_update_Logs]
   ON [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING]
   for update
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;



INSERT INTO [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger]
           ([ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG]
           ,[Status])
   
Select  [ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG],'Before Update' from deleted;

END

GO


 Update Trigger: 


USE [BBInfinity]
GO

/****** Object:  Trigger [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_After_update_Logs]    Script Date: 7/2/2015 12:20:36 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:                <Author,,Name>
-- Create date: <Create Date,,>
-- Description:        <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_After_update_Logs]
   ON [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING]
   after update
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;



INSERT INTO [dbo].[USR_PAPERSAVE_REVENUEBATCH_MAPPING_trigger]
           ([ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG]
           ,[Status])
   
Select  [ID]
           ,[COMMITEDBATCHREVENUEID]
           ,[ADDEDBYID]
           ,[CHANGEDBYID]
           ,[DATEADDED]
           ,[DATECHANGED]
           ,[TSLONG],'After Update' from inserted;

END








Tools and tricks which can save your time while doing troubleshooting

Tools and tricks which can save your time while doing troubleshooting

When you work with support , the main thing is you need to learn is to save time. There are lots of tools which can save your time. I am going to mention all in this article which I used so far.

1) One Note 

Generally most fresher support engineers use notepad and notepad++ in their initial stage but there are lots of disadvantages of them. contents you write in notepad and ++ are not automatically saved. In notepad even don't have different pages , in ++ you have that but every time you need to save it.But tool I am going to show here is more efficient than that.

I am talking about One note , How it looks like:




Here , you can make note for every client/ for every case.

What I have been doing with one note , whenever I get new case I create new page with client name or with issue title and copy all details which I get from case notes or from tier 1 team member. I also copy all relavant kba links here , also if I get new credentials , machine details from client then will also copy here.

You will see all my work of one note in right panel. Also refer this below article to get more idea about one note.

https://support.office.com/en-za/article/Basic-tasks-in-Microsoft-OneNote-2013-da73c095-e082-4276-acf9-8728ca8b08ab


So go ahead and start , practice with this. I am sure you can save your time when you start using this instead of notepad/++

Advantage:
-> You can get all details very quickly as it displays everything in same frame
->You don't need to save when you write/ update your content this because  it saves your content automatically.

2) Difference Checker:

Many times while troubleshooting you need to compare new script/code  with old script/code that time this toll will be helpful to you.

This is online tool , below is link to open it . You will need to copy your old code/script and new code/script and you will find difference very quickly.

https://www.diffchecker.com/diff

Below is it look:





3) SQL Formatter:

This tool is important for doing formatting of your sql script. It makes your script in good format and using this you can also get quick idea where your script has an error.

Here is the link, this one is also online tool:

http://www.dpriver.com/pp/sqlformat.htm

How it looks like:



4)Make folders in your outlook: 

 When you work with support tasks , you get everyday lots of emails and you have to manage all these emails. By managing this things you can find important emails very quickly.


Outlook is providing feature called create folder , you can create different folders like for your manager emails new folder , for your supervisor different folder , for code related emails new folder etc. And when you get emails , you can move them to relevant folders. You can do this manually or also you can create some rules which can move your emails to relevant folders automatically. I generally do manually move.

How my outlook looks like:





Below link will give you idea how to move email to relevant folders automatically:

https://support.office.com/en-za/article/Manage-email-messages-by-using-rules-c24f5dea-9465-4df4-ad17-a50704d66c59


5) Snipping tool

While doing troubleshooting many times you need to capture some screen shots of errors , script etc.
That time you can use print screen option but tool I am talking about is efficient than print screen, that is snipping tool. Snipping toll provides quick capture of screen  , you can capture any portion of screen , generally in print screen you will get all portion of your screen and then you need to crop it according to your requirement but in snipping it's easy to do with one step only (don't know if print screen also provides any short cut to capture few portion of screen , I am used to with snipping tool)

Here is how it looks like:



You can place it in your machine's task bar so whenever you need , you can quickly use it and it will definitely save your time and will help you to capture all needed things quickly.