Skip to content

Instantly share code, notes, and snippets.

View r1d3rzz's full-sized avatar
💻
Working from home

MyintThwayKhine r1d3rzz

💻
Working from home
View GitHub Profile
@r1d3rzz
r1d3rzz / gist:7fe788e31d65ce54a69dcdddef3b410e
Created November 13, 2024 03:37
Check Mb Size DB Table
SELECT
s.Name AS SchemaName,
t.Name AS TableName,
p.rows AS NumRows,
CAST(ROUND((SUM(a.total_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Total_MB,
CAST(ROUND((SUM(a.used_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Used_MB,
CAST(ROUND((SUM(a.total_pages) - SUM(a.used_pages)) / 128.00, 2) AS NUMERIC(36, 2)) AS Unused_MB
FROM
sys.tables t
JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
@r1d3rzz
r1d3rzz / calInterestRate.sql
Created November 6, 2024 07:28
Calculate Interest Rate SQL
PRINCIPAL_AMOUNT*(INTEREST_RATE/100)/INT_BASIS*TERM
SELECT
s.session_id,
s.login_name,
s.host_name,
s.status,
s.last_request_start_time,
s.last_request_end_time,
r.cpu_time,
r.total_elapsed_time,
r.reads,
@r1d3rzz
r1d3rzz / gist:895f9ae551c4e809a8a17455d5d8dbf5
Created September 26, 2024 03:46
fix audit log in ssms
SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, GETUTCDATE(), CURRENT_TIMESTAMP), event_time) AS event_time_afterconvert,
getdate() 'Current_system_time'
,statement --for reason
,*
FROM fn_get_audit_file('D:\code\SSMS\Audit\*', DEFAULT, DEFAULT) WHERE action_id = 'LGIF' -- LGIF mean Login Fail
@r1d3rzz
r1d3rzz / gist:1f062f75d37c689ee8bc3923461b4812
Created September 18, 2024 06:34
config for datatable file export
$.extend(true, $.fn.dataTable.defaults, {
processing: true,
responsive: true,
mark: true,
order: [[0, "desc"]],
iDisplayLength: 5,
aLengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
layout: {
topStart: {
buttons: [
DTExec.exe /file "D:\filepath" /de "something"
use HRMS
go
update Employees set Department_Branch_Id = Departments.Department_Id
from Departments
WHERE Departments.Name = Employees.DepartmentName
// Assuming employee.PermanentEndDate is DateTime? (nullable DateTime)
if (employee.PermanentEndDate.HasValue)
{
var empPermanentEndDate = employee.PermanentEndDate.Value.Date; // Use .Date to ignore the time part
var today = DateTime.Today;
var previousDay = DateTime.Today.AddDays(-1);
if (empPermanentEndDate == previousDay && previousDay == today)
{
// Do something if empPermanentEndDate is the same as yesterday and today
BULK INSERT [dbo].[Designations]
FROM 'C:\Users\User\Desktop\Designation.csv'
WITH (
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2
);
@r1d3rzz
r1d3rzz / Get PreviousStartDateAndEndDate.sql
Created July 3, 2024 07:44
Get Previous StartDate And EndDate
DECLARE @CurrentDate DATE = GETDATE();
DECLARE @FirstDayOfPreviousMonth DATE;
DECLARE @LastDayOfPreviousMonth DATE;
-- Calculate the first day of the previous month
SET @FirstDayOfPreviousMonth = DATEADD(MONTH, DATEDIFF(MONTH, 0, @CurrentDate) - 1, 0);
-- Calculate the last day of the previous month
SET @LastDayOfPreviousMonth = EOMONTH(DATEADD(MONTH, -1, @CurrentDate));