Posts

Showing posts from July, 2024

Formula

WITH DateSequence AS (     SELECT CAST(GETDATE() AS DATE) AS BusinessDate     UNION ALL     SELECT DATEADD(DAY, -1, BusinessDate)     FROM DateSequence     WHERE DATEADD(DAY, -1, BusinessDate) > DATEADD(DAY, -14, GETDATE()) -- Generate enough days to cover weekends ), BusinessDays AS (     SELECT BusinessDate     FROM DateSequence     WHERE DATENAME(WEEKDAY, BusinessDate) NOT IN ('Saturday', 'Sunday') ) SELECT MIN(BusinessDate) AS TMinus5BusinessDay FROM (     SELECT BusinessDate, ROW_NUMBER() OVER (ORDER BY BusinessDate DESC) AS RowNum     FROM BusinessDays ) AS NumberedBusinessDays WHERE RowNum = 5 OPTION (MAXRECURSION 100);

PROCEDURE GetTopResults

CREATE PROCEDURE GetTopOrBottomResults     @N INT,              -- Accepts number of top/bottom results     @OrderType VARCHAR(10) -- Accepts 'Top', 'Bottom', or 'All' AS BEGIN     SET NOCOUNT ON;     -- Determine the number of rows in the table if 'All' is specified     DECLARE @TotalRows INT;     SET @TotalRows = (SELECT COUNT(*) FROM YourTable);     -- Handle the 'All' case by setting @N to the total number of rows     IF @OrderType = 'All'     BEGIN         SET @N = @TotalRows;     END     -- Determine the query to execute based on the @OrderType parameter     IF @OrderType = 'Top' OR @OrderType = 'All'     BEGIN         -- Select top N results ordered by SomeColumn         SELECT TOP (@N) *         FROM YourTable         ...

CurrencyReference Table

 -- Create the CurrencyReference table CREATE TABLE CurrencyReference (     CurrencyDescription NVARCHAR(100),     CurrencyShortName CHAR(3) ); -- Insert all possible currency descriptions and their corresponding ISO codes INSERT INTO CurrencyReference (CurrencyDescription, CurrencyShortName) VALUES     ('Afghan Afghani', 'AFN'),     ('Albanian Lek', 'ALL'),     ('Algerian Dinar', 'DZD'),     ('Angolan Kwanza', 'AOA'),     ('Argentine Peso', 'ARS'),     ('Armenian Dram', 'AMD'),     ('Aruban Florin', 'AWG'),     ('Australian Dollar', 'AUD'),     ('Azerbaijani Manat', 'AZN'),     ('Bahamian Dollar', 'BSD'),     ('Bahraini Dinar', 'BHD'),     ('Bangladeshi Taka', 'BDT'),     ('Barbadian Dollar', 'BBD'),     ('Belarusian Ruble', 'BYN'),     ('Belize Dollar', ...

Python Dash App: Calculate Difference

 # Import necessary libraries import dash from dash import dcc, html from dash.dependencies import Input, Output, State # Initialize the Dash app app = dash.Dash(__name__) # Global default values DEFAULT_VALUE1 = 1000 DEFAULT_VALUE2 = 400 # Function to calculate the difference between two values def calculate_difference(value1, value2):     return value1 - value2 # Define the layout of the app app.layout = html.Div([     html.Div([         html.Label('Value1'),         dcc.Input(             id='input-box-1',              type='number',              value=DEFAULT_VALUE1,              placeholder='Enter first value'         ),     ]),     html.Div([         html.Label('Value2'),         dcc.Input(     ...

PowerShell Function to get the last business day from today's date

# Function to get the last business day from today's date function Get-LastBusinessDay {     # Get today's date     $today = Get-Date     # Determine the last business day based on today's day of the week     switch ($today.DayOfWeek) {         'Monday'   { $lastBusinessDay = $today.AddDays(-3) } # Last Friday         'Sunday'   { $lastBusinessDay = $today.AddDays(-2) } # Last Friday         'Saturday' { $lastBusinessDay = $today.AddDays(-1) } # Last Friday         default    { $lastBusinessDay = $today.AddDays(-1) } # Previous day     }     # Return the last business day     return $lastBusinessDay } # Get and print the last business day $lastBusinessDay = Get-LastBusinessDay Write-Output "The last business day from today's date is: $($lastBusinessDay.ToString('yyyy-MM-dd'))"