Tuesday, December 10, 2024

Monday, December 9, 2024

Check Database Session Queries

 SQL SERVER: Check Database Queries which are taking time to execute. 

--https://blog.sqlauthority.com/2021/09/20/sql-server-troubleshooting-high-cpu/


SELECT TOP 50 s.session_id,

           r.status,

           r.cpu_time,

           r.logical_reads,

           r.reads,

           r.writes,

           r.total_elapsed_time / (1000 * 60) 'Elaps M',

           SUBSTRING(st.TEXT, (r.statement_start_offset / 2) + 1,

           ((CASE r.statement_end_offset

                WHEN -1 THEN DATALENGTH(st.TEXT)

                ELSE r.statement_end_offset

            END - r.statement_start_offset) / 2) + 1) AS statement_text,

           COALESCE(QUOTENAME(DB_NAME(st.dbid)) + N'.' + QUOTENAME(OBJECT_SCHEMA_NAME(st.objectid, st.dbid)) 

           + N'.' + QUOTENAME(OBJECT_NAME(st.objectid, st.dbid)), '') AS command_text,

           r.command,

           s.login_name,

           s.host_name,

           s.program_name,

           s.last_request_end_time,

           s.login_time,

           r.open_transaction_count

FROM sys.dm_exec_sessions AS s

JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id CROSS APPLY sys.Dm_exec_sql_text(r.sql_handle) AS st

WHERE r.session_id != @@SPID

ORDER BY r.cpu_time DESC




Thursday, September 26, 2024

Clean Code 𝗖𝗹𝗲𝗮𝗻 𝗖𝗼𝗱𝗲 𝗧𝗶𝗽s - 𝗢𝘃𝗲𝗿𝗰𝗼𝗺𝗶𝗻𝗴 𝗕𝗼𝗼𝗹𝗲𝗮𝗻 𝗕𝗹𝗶𝗻𝗱𝗻𝗲𝘀𝘀

 public void ProcessOrder(int orderId, bool applyDiscount)

{

    if(applyDiscount)

    {

            //Apply Discount to the order

    }

        // Process the order here

}

ProcessOrder(1000, applyDiscount: true);


Clean Code:

public enum DiscountOption

{

    None,

    ApplyDiscount

}


public void ProcessOrder( int orderId, DiscountOption discountOption)

{

    if(discountOption == DiscountOption.ApplyDiscount)

        {

                // Apply discount to the order

        }

// Process the order

}

ProcessOrder(1000, DiscountOption.ApplyDiscount);

Saturday, June 8, 2024

Data-Table to List

 Auto increment in DataTable to List





public JsonResult GetProductCategoryList()

        {

            try

            {

                List<ProductCategoryViewModel> List_ProdCatViewModel = new List<ProductCategoryViewModel>();


                //var param = new { CompanyId = LoggedInCompId };

                //var CategoryList = productCategoryService.GetAll().Where(x => x.IsRemoved == false);

                var CategoryList = spQueryService.GetDataWithoutParameter("SP_Get_ProductCategoryListWithType");

                var count = 0;


                List_ProdCatViewModel = CategoryList.Tables[0].AsEnumerable()

                .Select(row => new ProductCategoryViewModel

                {

                    rowSl = (++count).ToString(),

                    ProdCatId = row.Field<int>("ProdCatId"),

                    ProdTypeName = row.Field<string>("ProdTypeName"),

                    ProdCatName = row.Field<string>("ProdCatName"),

                    ProdCatNameOther = row.Field<string>("ProdCatNameOther"),

                    DepriciateValue = row.Field<decimal?>("DepriciateValue"),


                }).ToList();


                return Json(List_ProdCatViewModel, JsonRequestBehavior.AllowGet);

            }

            catch (Exception ex)

            {

                return Json(new { Result = "ERROR", Message = ex.Message }, JsonRequestBehavior.AllowGet);

            }

        }

Tuesday, May 28, 2024

Remove First 3 character

 Declare @str nvarchar(23) = '04.99991.03.001.00101'

SELECT RIGHT(@str, LEN(@str)-3)


Result: 99991.03.001.00101


Saturday, April 27, 2024

split string to TABLE

 








ALTER FUNCTION [pksf].[fn_SplitString]

(    

      @Input NVARCHAR(MAX),

      @Character CHAR(1)

)


RETURNS @Output TABLE (

      Item NVARCHAR(1000)

)


AS

BEGIN

      DECLARE @StartIndex INT, @EndIndex INT

 

      SET @StartIndex = 1

      IF SUBSTRING(@Input, LEN(@Input) - 1, LEN(@Input)) <> @Character

      BEGIN

            SET @Input = @Input + @Character

      END

 

      WHILE CHARINDEX(@Character, @Input) > 0

      BEGIN

            SET @EndIndex = CHARINDEX(@Character, @Input)

           

            INSERT INTO @Output(Item)

            SELECT SUBSTRING(@Input, @StartIndex, @EndIndex - 1)

           

            SET @Input = SUBSTRING(@Input, @EndIndex + 1, LEN(@Input))

      END

 

      RETURN

END


Tuesday, January 23, 2024

Salary Second Highest

Second Highest Salary Department Wise. Group by 




select * from

(

select EmpId, EmpName, Salary, Department,

ROW_NUMBER() Over (Partition by Department Order by Salary Desc) AS SalaryRank

from Emp

) dd

where SalaryRank = 2 






Tuesday, December 26, 2023

Next Report: Update Table

 


step 1: 


declare @sql varchar(max);



DECLARE @DateName nvarchar(100)


SET @DateName=  '[NextReport].[dbo].NXTRPTEmployeeProfile_' + CAST( GetDate()  as NVARCHAR(12) );

SELECT @DateName = REPLACE(@DateName, ' ', '')

 --SELECT @DateName

 Set @sql = 'SELECT * INTO ' +  @DateName +' FROM [NextReport].[dbo].NXTRPTEmployeeProfile ';


 EXECUTE(@sql)

 

 

 step 2: 

 

 Drop Table [NextReport].[dbo].[NXTRPTEmployeeProfile]

 

 

 Step: 

 if (SELECT count(1) FROM NXTActiveEmployee) > 0

BEGIN

SELECT 1

END

ELSE

BEGIN

TRUNCATE TABLE NXTActiveEmployee


INSERT INTO NXTActiveEmployee

SELECT EmployeeCode FROM Employee WHERE EmployeeStatus = 'A'

   

   END


Sunday, December 17, 2023

All Steps For Next Report Table Update

 



--Step : 1


declare @sql varchar(max);



DECLARE @DateName nvarchar(100)


SET @DateName=  'NXTRPTEmployeeProfile' + CAST( GetDate()  as NVARCHAR(12) );

SELECT @DateName = REPLACE(@DateName, ' ', '')

 

 Set @sql = 'SELECT * INTO ' +  @DateName +' FROM NXTRPTEmployeeProfile ';


 EXECUTE(@sql)




 --step 2: 


 Drop Table NXTRPTEmployeeProfile


 --step 3:


 SELECT * INTO NXTRPTEmployeeProfile FROM EmpProfile

 

NextReport Update Table

 declare @sql varchar(max);



DECLARE @DateName nvarchar(100)


SET @DateName=  '[NextReport].[dbo].NXTRPTEmployeeProfile' + CAST( GetDate()  as NVARCHAR(12) );

SELECT @DateName = REPLACE(@DateName, ' ', '')

 --SELECT @DateName

 Set @sql = 'SELECT * INTO ' +  @DateName +' FROM [NextReport].[dbo].NXTRPTEmployeeProfile ';


 EXECUTE(@sql)



 

Backup Tables by Date

 


declare @sql varchar(max);



DECLARE @DateName nvarchar(100)


SET @DateName=  'NXTRPTEmployeeProfile' + CAST( GetDate()  as NVARCHAR(12) );

SELECT @DateName = REPLACE(@DateName, ' ', '')

 

 Set @sql = 'SELECT * INTO ' +  @DateName +' FROM NXTRPTEmployeeProfile ';


 EXECUTE(@sql)


Thursday, August 31, 2023

httpclient request with Access Token and payloads:

 httpclient request with Access Token and payloads:



 var param = new

            {


                documentNumber = "1317915213594",

                motherName = "Amena",

                dateOfBirth = "01/23/1985"


            };

var dataString = JsonConvert.SerializeObject(param);

            string accessToken_ = userDatas.accessToken;


            var client = new HttpClient();

            var request = new HttpRequestMessage(HttpMethod.Post, "http://104.198.53.36:8080/UW/app/erp/duplicationCheck");

            request.Headers.Add("Authorization", accessToken_);

            var content_ = new StringContent(dataString, null, "application/json");

            request.Content = content_;

            var response_ = await client.SendAsync(request);

            response_.EnsureSuccessStatusCode();


Monday, August 14, 2023

Knowledge

 Knowledge itself is a potential power. Knowledge combined with action is real power. 

Wednesday, August 9, 2023

Saturday, July 15, 2023

Remove Mandatory field from model

Remove the Mandatory field from the model:                


ModelState.Remove("SyncMonth");

ModelState.Remove("NotSyncMonth");


            if (!ModelState.IsValid)

                return GetErrorMessageResult("Warning! You must fill all the required fields");


Wednesday, June 14, 2023

Json Web Tokens jwt.io

 https://jwt.io/

JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.











Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.