After logging into your db account, If you have proper permission, the account having the SQL Server Agent. Then extend the SQL Server Agent , it displays the Job Folder. Right Click and create a Job like below,


Click the New Job option, then it is shows like below



It is having six options. They are General,Steps,Schedules, Alerts, Notifications and Targets

The General Tab is Explained the above figure.

Steps Tab: Now, we will define the steps. Click the New button,

 

 

 

It is having 2 options General and Advanced.  In General, we will give the execution script. That type may be in T-SQL , PowerShell, CmdExec, SSIS Package, etc.,


and Advanced option,


We may create the no. of steps



Schedule Tab:

In this Tab we will schedule the time and date as per our need. see the belows,





Notification Tab



Remaing Tabs are used based on our need.

Finally click ok button thats all the job creation. 
 


Pivot :

- We can turn Columns into rows. So that single columns Values are converted into Column Names
- When we pivot the table we must use aggregated functions.
                  

CREATE TABLE #tmpNormalTable(CustomerId int,CustomerName varchar(20),NoOfProjects int)

INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12011,'HealthCare',1)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12000,'Insurance',2)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12011,'HealthCare',21)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12011,'HealthCare',12)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12000,'Insurance',30)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (12011,'HealthCare',6)
INSERT INTO #tmpNormalTable(CustomerID,CustomerName,NoOfProjects) VALUES (11100,'Finance',100)



SELECT * FROM #tmpNormalTable

--Get Dymanic Column Names

DECLARE @columns NVARCHAR(2000)
SELECT  @columns = STUFF(
                                                                   (
                                                                             SELECT DISTINCT TOP 100 PERCENT '],[' + t2.CustomerName
                                                                             FROM  #tmpNormalTable AS t2
                                                                             ORDER BY '],[' + t2.CustomerName
                                                                             FOR XML PATH('')
                                                                   )
                                                                   , 1, 2, '') + ']'


DECLARE @query NVARCHAR(4000)
SET @query = N'SELECT CustomerID,'+ @columns + '
FROM
(
          SELECT 
                             t1.CustomerID,
                             t1.CustomerName,
                             t1.NoOfProjects
          FROM #tmpNormalTable AS t1
) p
PIVOT
(
sum([NoOfProjects])
FOR CustomerName IN
( '+
@columns +' )
) AS pvt
ORDER BY CustomerID;'

EXEC(@query)



UNPIVOT :

- We can turn Rows into Columns. So that the Column names are converted into single column values.

CREATE TABLE #tmpNormalUnPivot(CustomerId int,Finance tinyint,Healthcare tinyint,Insurance tinyint)

INSERT INTO #tmpNormalUnPivot(CustomerId,Finance,Healthcare,Insurance) VALUES (11100,100,null,null)
INSERT INTO #tmpNormalUnPivot(CustomerId,Finance,Healthcare,Insurance) VALUES (12000,null,7,null)
INSERT INTO #tmpNormalUnPivot(CustomerId,Finance,Healthcare,Insurance) VALUES (12011,null,null,12)

select * from #tmpNormalUnPivot



SELECT  CustomerID,CustomerName,NoOfProjects
FROM
(
          SELECT CustomerID,Finance,Healthcare,Insurance
          FROM #tmpNormalUnPivot
)p
UNPIVOT
(NoOfProjects FOR CustomerName IN (Finance,Healthcare,Insurance)
) AS Unpvt

Step 1:
First Create a Function for getting Object which is using linked server

CREATE FUNCTION [dbo].[fuGetLinkedServerNameInSPs](@ServerName varchar(MAX))
RETURNS @Return TABLE (XName varchar(200),XType Varchar(3))
AS
BEGIN
;WITH cteTableValueCollection(Name,Type)
AS
(
SELECT DISTINCT o.name, o.xtype FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id WHERE c.TEXT LIKE '%' + @ServerName + '%'
)
INSERT @Return SELECT Name,Type FROM cteTableValueCollection
RETURN
END

Step 2 :

Getting Linked server Names in DB.

create table #tmpLinkedServerNames(SeqID int Identity(1,1),SRV_Name varchar(100),SRV_ProviderName varchar(50),SRV_Product varchar(50),SRV_Datasource Varchar(50),
SRV_Providerstring varchar(50),SRV_Location varchar(50),SRV_Cat varchar(50))

insert into #tmpLinkedServerNames(SRV_Name,SRV_ProviderName,SRV_Product,SRV_Datasource,SRV_Providerstring,SRV_Location,SRV_Cat) exec sp_linkedservers

select * from #tmpLinkedServerNames


Getting Whole List

Declare @MaxCount tinyint,@NextCount tinyint,@LinkedServerName Varchar(50)
Declare @spList Table(LinkedServerName Varchar(20),objectName Varchar(50),ObjectType Varchar(3))

-- Get the Linked Server Count
select @MaxCount=MAX(seqid) from #tmpLinkedServerNames

set @NextCount = 1
while(@MaxCount >= @NextCount)
begin
-- One by one process
select @LinkedServerName = SRV_Name From #tmpLinkedServerNames where SeqID = @NextCount

insert into @spList(LinkedServerName,objectName,ObjectType) select @LinkedServerName,XName,XType from [dbo].[fuGetLinkedServerNameInSPs](@LinkedServerName)

Set @NextCount = @NextCount + 1

end

Now the Table display the Entire list that is having linked server name.

select * from @spList

Go to File -- > New -- > Project -- >Visual C# -- > Windows -- > Windows Service .
Then Create a New Project. It shows(Service1.cs),


 Then Right Click and  Click the Add Installer bar, ProjectInstaller.cs File will be created



Its having  two controls,  ServiceProcessInstaller1, and ServiceInstaller1

In ServiceProcessInstaller1 == > Go to Properties and Modify Account as Local Service . It is aoid the Set Service Login prompt being asked about the system username and password





In ServiceInstaller1 ==> Go to Properties and Modify StartType as Automatic , Servicename à Your Service Name , Display Name ( This name is shown in the Services), Description (This Name is shown in the Services)



Right Click Windows Service Project and Add Folder and file called CommonBehaviours.cs

CommonBehaviours.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WindowsService.Function
{
    public class WriteToFile
    {
        public void WriteToFile1()
        {
            string strDateTime = DateTime.Now.ToString();
            StreamWriter sw = new StreamWriter(Path.Combine("D:\\temp\\", "Suresh.txt"), true);
            sw.WriteLine(strDateTime);

            sw.Close();
        }
    }

}
Service1.cs
using System;
using System.ServiceProcess;
using System.Timers;
namespace TestWindowsService
{
    partial class Service1 : ServiceBase
    {   //Make the service at particular time period
        Timer TimerObj = new Timer(ConvertMinutesToMilliseconds(30));
        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {   // TODO: Add code here to start your service.
            TimerObj.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            TimerObj.Enabled = true;
        }
        protected override void OnStop()
        {   // TODO: Add code here to perform any tear-down necessary to stop your service.
            TimerObj.Enabled = false;
        }
        protected void OnElapsedTime(object source, ElapsedEventArgs e)
        {  //Write the current datetime to the file
           WindowsService.Function.WriteToFile objWriteToFile = new WindowsService.Function.WriteToFile();
        }
        public static double ConvertMinutesToMilliseconds(double minutes)
        {
            return TimeSpan.FromMinutes(minutes).TotalMilliseconds;
        }
    }
}


How to start service in Code

Go to ServiceInstaller1 -- > Create an event , Write a code to start the service like shown below.




create Service Installer

Ritht Click the Projects Solution -- > Add New Project -- > Go to Other Project Types -- > Setup and Deployment -- > Choose the Setup



Then follow the below steps



Then Double Click the Application Folder
Then Double Click the Primary output (from your service name)

Press ok . Then see the Setup Properties F4 (need to setup like below).It shown like below



Manufacturer will come in path as "C:\Program Files\ManufacturerValue"
Title will come in Setup Wizard

The Right Click and go to the Properties Set the Configurateion dropdown and Configuration Manager to Release Mode

Then our Installation steps :





Then Click Next and Finally Complete the Installation (click Close)

Finally the services is shown below


Now the Service is created and run successfully right.

Let's suppose you want to give a warning information to the clients:
<asp:GridView ID="GridView1" DataKeyNames="ID" ...>
<Columns>
<asp:TemplateField HeaderText="ButtonColumn">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Delete" OnclientClick="<%#Eval("Primary Key","return confirm('Are you sure to delete Record {0}?');")%>"/>
</ItemTemplate>
</asp:TempalteField>
</Columns>
</asp:GridView>

Example :
<asp:ImageButton ID="imgView" ImageUrl="../Images/view.jpg" runat="server"
OnClientClick='<%# Eval("Accname", "Openpopup(\"{0}\"); return false;") %>'>
</asp:ImageButton>



Add SET NOCOUNT ON to the top of the trigger definition. This will suppress the additional rows affected message that emanates from the trigger and confuses SSMS. 
otherwise, some times its through an errror :
The row value(s) updated or delted either do not make the row  unique or they alter multiple rows
CREATE TRIGGER trgProcessHistory
ON M_Process 
AFTER UPDATE 
AS 
SET NOCOUNT ON;
IF( 
 UPDATE (Rate) OR UPDATE (LocationID) 
 OR UPDATE (LOBID) OR UPDATE (ProcessDescription) 
 OR UPDATE (System) OR UPDATE (Active) 
 OR UPDATE (CreatedBy) OR UPDATE (CreatedOn) 
 OR UPDATE (ModifiedBy) OR UPDATE (ModifiedOn)
   )
BEGIN
 INSERT INTO dbo.M_ProcessHistory(
   SeqID,LOBID,LocationID,ProcessDescription,System,Rate,Active,
   CreatedBy,CreatedOn,ModifiedBy,ModifiedOn,UpdatedOn,
   DBLoginName,ClientIP)
 
 SELECT  SeqID,LOBID,LocationID,ProcessDescription,System,Rate,Active,
   CreatedBy,CreatedOn,ModifiedBy,ModifiedOn,getdate(),
   user_name(),Host_Name()
 FROM deleted ; 
 
END;