Search the Blog

Showing posts with label Software Development. Show all posts
Showing posts with label Software Development. Show all posts

Monday, September 7, 2020

SQL server Upgrade

 

When you upgrade to a new version of SQL Server, there are some critical things you should do to help avoid any surprise SQL Server performance issues. I mean new version  of SQL Server is 2016,2017 or 2019, Because Microsoft  closed its support up to some extent to older version


Why need the Requirement to upgrade the Version?

Basically it is because Microsoft ended Its support of some versions.

There are two type of Support

1- MainStream Support

2- Extended Support


SQL Server Versions

MainStream Support

Extended Support

SQL Server 2005

April 12, 2011

April 12, 2016

SQL Server 2008 or R2

July 8, 2014

July 9,2019

SQL Server 2012

July 11, 2017

July 12, 2022

SQL Server 2014

July 9, 2019

July 9, 2024

SQL Server 2016

July 13, 2021

July 14, 2026

SQL Server 2017

Oct 11, 2022

Oct 12, 2027

SQL Server 2019

July 1, 2025

Aug 1, 2030


For Upgrading any Version there are some preparations which need to be taken care.

1- Find the Upgrade Blockers. 

2- Clear Understanding of Version and Editions.

3- Clear Understanding of Features introduced and obsolete

3- Make a List of objects which use the features which  are obsolete from the newer version and currently in use.

4- Clear Hardware Requirement for newer Versions. 






















For this Activity i am upgrading the Server from 2012 to 2017.


Process to Upgrade the SQL Server Version.

There are 3 ways to upgrade

  1. - In-Place Upgrade

  2. - Side-by-Side Upgrade

  3. - Rolling Upgrade


Steps for an In-Place Upgrade 

In-place upgrades are the easiest to perform, but the most difficult to rollback should there be any issues. The steps involved in an in-place upgrade are as follows:

  1. Verify that backups exist for all databases (user and system). 

  2. Review the list of requirements for SQL server 2017 and install whatever is needed.

  3. Install SQL Server 2017 

  4. Restore the Backup

Side-by-Side Upgrade

  • 1- Backup all the database

  • 2-Script out any and all necessary system objects.

            3-Review the list of requirements for SQL server 2017 and install whatever is needed.

  • 4- Run the script to create the Object

  • 5-Select database(s) to migrate and it take offline. 

  • 6-Migrate database to new instance. Repeat for each database.

  •  

 

 

 

Rolling Upgrade


1- Select any High-Availability 

2- Install new Server instance 2017 and make it  as a Secondary node

3- Fail the Primary Node now New Instance will be active and will be Primary Node

 

Checklist need to Perform Before Planning to Upgrade about version of Server


1-Checking of Deprecated Features  in new version

SELECT * FROM sys.dm_os_performance_counters   WHERE object_name  = 'MSSQL$JFT:Deprecated Features   

2- Get the List top indexes which are in use maximum times in the current version.

SELECT OBJECT_NAME(IX.OBJECT_ID) Table_Name

      ,IX.name                     AS Index_Name

      ,IX.type_desc                 AS Index_Type

      ,SUM(PS.[used_page_count]) * 8     IndexSizeKB

      ,IXUS.user_seeks AS             NumOfSeeks

      ,IXUS.user_scans AS             NumOfScans

      ,IXUS.user_lookups AS             NumOfLookups

      ,IXUS.user_updates AS             NumOfUpdates

      ,IXUS.last_user_seek AS         LastSeek

      ,IXUS.last_user_scan AS         LastScan

      ,IXUS.last_user_lookup AS         LastLookup

      ,IXUS.last_user_update AS         LastUpdate

FROM sys.indexes IX

INNER JOIN sys.dm_db_index_usage_stats IXUS 

ON IXUS.index_id = IX.index_id AND IXUS.OBJECT_ID = IX.OBJECT_ID

INNER JOIN sys.dm_db_partition_stats PS 

on PS.object_id=IX.object_id

WHERE OBJECTPROPERTY(IX.OBJECT_ID,'IsUserTable') = 1

GROUP BY 

OBJECT_NAME(IX.OBJECT_ID) ,

IX.name ,

IX.type_desc ,

IXUS.user_seeks ,

IXUS.user_scans ,

IXUS.user_lookups,

IXUS.user_updates ,

IXUS.last_user_seek ,

IXUS.last_user_scan ,

IXUS.last_user_lookup ,

IXUS.last_user_update

3- Current Used Space at current instance and Available Space in the new instance.

4- Current OS Hardware Configuration.

5- Scripting of all user defined Objects.

 

Sunday, July 14, 2019

MIS Queries Sql Server

This post have all the Impoortant Queries which an organizastion Management requires to analysis the Organization Grouth and culture.

 Top 100+ Sql Server Interview Questions

 

MIS Queries Sql Server

Employee List  MIS Query

Select
   s.Subtrans_Name,
   b.Full_Name,
   b.cand_code,
   c.Para_Description Department,
   d.Para_Description Designation,
   e.Para_Description Leave_Type,
    a.fullHalf_Leave,
    convert(nvarchar,a.Fromdt,103),
    convert(nvarchar,a.Todt,103),
    isnull(convert(nvarchar,a.fromtime,108),''),
    isnull(convert(nvarchar,a.totime,108),'')
    from main_Account s,
    Employee_register a
    inner join Employee_Master b on a.co_Code = b.co_Code and a.empno = b.ID
    left outer join Parameter_Department c on b.dept_code = c.ID
    left outer join parameter_designation d on b.desi_code = d.urn_no
    left outer join Parameter_Leave_Type e on a.Leavetype_ID = e.URN_No
 
 where
    s.co_Code = a.co_code and s.Subtrans_Code=a.DB_CODE
    and a.Fromdt>=@fromdate and a.Todt<=@todate



SQL MIS Query for Account Ledger


SELECT A.AC_NAME,
A.AC_SHORTNAME,
A.AC_TYPE,
A.CITY,
A.PERSON_STATE,
A.CONTRY,
A.GST_NO
FROM
ACCOUNT_MASTER A,
BALANCESHEETGROUP_MASTER B
WHERE
 A.GR_CODE=B.Code
AND A.ACCOUNT_STATUS = 'APPROVED'




SQL QUERY Pending dispatch instruction

select
 e.CO_NAME as "Unit",
a.OA_Status as "Status",
d.AC_NAME as"Customer Name",
d.Ac_ShortName as "Bill to (Customer Code)",
'' as "Shipped to (Customer Code)",
f.DESCRIPTION as "Customer Group",
 a.OA_NO as"Sale Order No",
CONVERT(nvarchar,a.OA_DATE,103) as "Sale Order Date",
c.ALT_NAME as "Item Code",
c.IT_NAME as "Item Description",
g.Para_Description as "UOM",
'' as "Warehouse",b.ALT_QTY as "Ordered Quantity",
b.ALT_RATE as "Item Rate",
'' as "Shipped Quantity",
'' as "Back Order Quantity",
'' as "Required Date"
 from
order_mast a,
order_details b,
Item_Master c,
account_master d,
co_mast e,
Account_category f,
Measurement_Unit g
where a.urn_no=b.urn_no
and b.it_code=c.it_code
and a.oa_custco=d.sr_no
and a.co_code=e.co_code
and d.Party_Category_ID=f.id
and b.ALT_UNIT_ID=g.ID
and a.oa_date>=@fromdate and a.oa_date<=@todate






SQL Query Pending Purchase Order Details


@fromdate datetime=null,
@todate datetime=null,



SELECT
 C.CO_NAME AS 'Unit',
a.PO_Status as 'Status',
a.Pur_Order_No as 'PO No',
convert(nvarchar,a.Pur_Order_Date,103) as 'PO Date',
F.DESCRIPTION AS 'Supplier Group',
D.AC_NAME AS 'Supplier Name',
E.ALT_NAME AS'Item Code',
E.IT_NAME AS 'Item Description',
B.ALT_UNIT AS 'UOM',B.ALT_QTY AS'Order Quantity',
(
    select isnull(sum(alt_qty),0) from
 Purchase_Inward_Det
where From_URN_No=b.URN_No and From_Item_Sr_No=b.pur_order_srno )
AS 'Received Quantity',
b.ALT_QTY-(
select
isnull(sum(alt_qty),0) from
Purchase_Inward_Det
where From_URN_No=b.URN_No and From_Item_Sr_No=b.pur_order_srno) AS 'Pending Quantity',B.ALT_RATE AS 'Rate',B.Final_Amt AS 'Value',isnull(convert(nvarchar,b.Req_Date,103),'') as 'Required Date',
case when b.ALT_QTY-(select isnull(sum(alt_qty),0)
from Purchase_Inward_Det where
From_URN_No=b.URN_No and
From_Item_Sr_No=b.pur_order_srno)<0 then 0
else isnull(
(datediff(day,b.Req_Date,(SELECT GETDATE()))),0) end as 'Delays'

FROM
PURCHASE_ORDER_MASTER A,
PURCHASE_ORDER_DETAILS B ,
ACCOUNT_MASTER D,
ITEM_MASTER,
PARTY_CATEGORY F
WHERE A.URN_NO=B.ID
AND A.Supp_Code=D.SR_NO
AND B.IT_CODE=E.IT_CODE
AND D.PARTY_CATEGORY_ID=F.ID
and a.CO_CODE
and a.Pur_Order_Date>=@fromdate and a.Pur_Order_Date<=@todate



SQL Query to track the details of any item

declare @it_code varchar(50)
set @it_code='A005123'
select * from (
select type,type_date,type_no,Location_Name,ALT_QTY,Entry_Status,Item_Stock_No,Para_Code,item_code from Item_Stock
union
select  'Request' as type,a.Req_Date as type_date,a.URN_No as type_no,'Request for issue' as Location_Name,b.ALT_QTY as [ALT_QTY],a.Req_Status as [Entry_Status],'0' as [Item_Stock_No],'Para_Code' ,b.IT_CODE as [item_code]
from Requisition_Detail b
left outer join Requisition_mast a on a.URN_No=b.URN_No
left outer join ItemMaster c on b.it_code=c.IT_CODE

) as A where item_code=@it_code order by type_date


SQL Query for checking the mismatch of common data in two tables

select * from Item_Stock a
left outer join Purchase_GRN_Det b on a.type_no=b.URN_No and a.item_code=b.IT_CODE
where a.para_code<>b.Para_Code





SQL Query to make GST Report HSN Code Wise 



select 'Sale' as [Sales Account],
sum(case when a.ac_code='ACC00B001069' Then a.Credit_Amount else 0 end) as [Basic],
sum(case when a.ac_name like '%SGST%OUTPUT%' then a.Credit_Amount else 0 end) as [SGST],
sum(case when a.ac_name like '%CGST%OUTPUT%' then a.Credit_Amount else 0 end) as [CGST],
sum(case when a.ac_name like '%IGST%OUTPUT%' then a.Credit_Amount else 0 end) as [IGST]
 from
ledr_data  a
left outer join acct_mast b on a.AC_CODE=b.SR_NO
 where b.ac_type='General' and urn_no like 'MSI%'  and Trans_Type='S'
union
select 'Purchase' as [Sales Account],
sum(case when (a.ac_name like '%Purchase Account%' or a.ac_name like '%Invention Toolings%') Then a.DEBIT_Amount else 0 end) as [Basic],
sum(case when a.ac_name like '%SGST%INPUT%' then a.DEBIT_Amount else 0 end) as [SGST],
sum(case when a.ac_name like '%CGST%INPUT%' then a.DEBIT_Amount else 0 end) as [CGST],
sum(case when a.ac_name like '%IGST%INPUT%' then a.DEBIT_Amount else 0 end) as [IGST]
 from
ledr_data  a
left outer join acct_mast b on a.AC_CODE=b.SR_NO
 where a.urn_no like 'MPF%' and  (b.ac_type='General' or b.sr_no='ACC00A000042')  and Trans_Type='P'
 union
select 'Debit Note' as [Sales Account],
sum(case when (b.ac_type like '%General%') Then a.DEBIT_Amount else 0 end) as [Basic],
sum(case when a.ac_name like '%SGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%SGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [SGST],
sum(case when a.ac_name like '%CGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%CGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [CGST],
sum(case when a.ac_name like '%IGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%IGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [IGST]
 from
ledr_data  a
left outer join acct_mast b on a.from_ledger_code=b.SR_NO
 where a.urn_no like 'DRN%' and  (b.ac_type='General' )
 --select * from LEDR_DATA  where   urn_no like 'drn01A000266%'
  union
select 'Credit Note' as [Sales Account],
sum(case when (b.ac_type like '%General%') Then a.DEBIT_Amount else 0 end) as [Basic],
sum(case when a.ac_name like '%SGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%SGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [SGST],
sum(case when a.ac_name like '%CGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%CGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [CGST],
sum(case when a.ac_name like '%IGST%OUTPUT%' then a.DEBIT_Amount else CASE WHEN  a.ac_name like '%IGST%input%' THEN (-a.DEBIT_Amount) ELSE 0 end END ) as [IGST]
 from
ledr_data  a
left outer join acct_mast b  on a.from_ledger_code=b.SR_NO
 where a.urn_no like 'CRN%' and  (b.ac_type='General' )
 --select * from LEDR_DATA  where   urn_no like 'drn01A000001%'



SQL Query to track Invoice with multiple join full code 


select a.urn_no,i1.alt_name,b.URN_No,i2.alt_name,c.URN_No,i3.alt_name,d.URN_No,i4.alt_name,e.URN_No,i5.alt_name from Invoice_DET a
left outer join Challan_DET b on a.from_urn_no=b.urn_no and a.From_Item_Sr_No=b.CHALLAN_SRNO
left outer join Dispatch_DET c on b.from_urn_no=c.urn_no and b.From_Item_Sr_No=c.DIS_SRNO
left outer join Order_Delivery_Schedule_Det d on c.from_urn_no=d.urn_no and c.From_Item_Sr_No=d.Sr_No
left outer join Order_Delivery_Schedule_Mast d1 on d.URN_No=d1.URN_No
left outer join OA_DET e on d1.OA_NO_ID=e.urn_no
left outer join itemmaster i1 on a.IT_CODE=i1.IT_CODE
left outer join itemmaster i2 on b.IT_CODE=i2.IT_CODE
left outer join itemmaster i3 on c.IT_CODE=i3.IT_CODE
left outer join itemmaster i4 on d.item_id=i4.IT_CODE
left outer join itemmaster i5 on e.IT_CODE=i5.IT_CODE
where a.urn_no='A000167'


SQL Query for tracking the details of particular transaction in log table 

select b.First_Name,b.Last_Name,a.Action_Title,a.Curr_DateTime from Web_User_Log_Details a
left outer join user_master b on a.ur_code=b.ur_code where urn_no='A005964'



SQL Query for Purchase Order details 

select distinct 

a.URN_No
,a.Pur_Order_Date  as "Date"
,isnull(a.Pur_Order_No,'') as "Doc No"
,c.ac_name as "Account Name"
,a.Ref_No as "Ref No",
s.Subtrans_Name as "Category",
a.Grand_Total as "Amount",
c.city as "City",
"Currency"=(g.Para_Description)
from
Purchase_Order_Mast a left outer join
Purchase_Order_Det b on a.CO_CODE = b.CO_CODE and a.URN_No = b.URN_No
left outer join
(select co_code,From_URN_No,From_Item_Sr_No,sum(alt_qty) alt_qty from Purchase_GRN_Det
group by co_code,From_URN_No,From_Item_Sr_No ) as forwrd 
on b.CO_CODE = forwrd.CO_CODE and b.URN_No = forwrd.From_URN_No
left outer join
(select co_code,From_URN_No,From_Item_Sr_No,sum(alt_qty) alt_qty from purchase_inward_det
group by co_code,From_URN_No,From_Item_Sr_No ) as forwrdInward
on b.CO_CODE = forwrdInward.CO_CODE and b.URN_No = forwrdInward.From_URN_No 
left outer join acct_mast c on a.CO_CODE =c.CO_CODE and a.Supp_Code =c.SR_NO  and c.acc_status = 'Approved'
left outer join LEDR_DATA f on (f.Ac_Code=a.Supp_Code or f.From_Ledger_Code=a.Supp_Code) and f.fyear=a.fyear and f.CO_CODE=a.CO_CODE
left outer join Parameter_Currency g on g.CO_CODE =a.CO_CODE and g.URN_No =a.SALE_CURRCO
left outer join Sub_Trans s on a.CO_CODE=s.CO_CODE and a.DB_CODE=s.Subtrans_Code
where  a.CO_CODE=@Prm_Co_Code
and a.Pur_Order_Date>=@fromdate and a.Pur_Order_Date<=@todate

Translate