Windows Screen Record
WindowsKey+ Alt + R
Recording Starts.
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
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);
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);
}
}
Declare @str nvarchar(23) = '04.99991.03.001.00101'
SELECT RIGHT(@str, LEN(@str)-3)
Result: 99991.03.001.00101
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
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
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
--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
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)
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)
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();
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");
https://jwt.io/
JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.
Windows Screen Record WindowsKey+ Alt + R Recording Starts.