Friday, December 14, 2018

Monday, October 29, 2018

Monday, September 3, 2018

SQL Server Format command (TSQL)

If you're going to use the SQL Server format command, please consider about it's performance hit. When compare it with the cast, and convert you can feel a big performance difference. It drags your query compilation comparably slow.

"format()" command is a really convince to use, but end result is bit scary.
With my experience, query that i wrote with the format takes around 30 sec, and the same query took only 11 sec without the format command.

i used it as follows (This is an example only)
Select format(getdate(),'yyyy-MM-dd')

replace with

Select cast(getdate() as date)

Friday, August 24, 2018

SQL Server Casting and Format commands

Select       cast('9:30 AM' as time) -- <-- this convert the string into a Time
       format ([First_call],'HH\:mm') --<-- This converts time into 24 hour clock format

Sunday, August 5, 2018

Get the previous dates in SQL server

select dateadd(dd,-x, cast(getdate() as date))
select dateadd(day,-x, cast(getdate() as date))
select dateadd(day,-x, getdate())

-- Replace x with your dates required. x could be - or +

  SELECT DATEADD(m, DATEDIFF(m, 0, GETDATE()), 0)   -- get the month start date

Select EOMONTH(getdate()) -- get last date of the month

Sunday, July 29, 2018

MySQl user grant

======================================

GRANT ALL PRIVILEGES ON `*`.* TO 'root_login'@'%' IDENTIFIED BY 'Pass@123' WITH GRANT OPTION

GRANT ALL PRIVILEGES ON `%`.* TO 'root_user'@'%' IDENTIFIED BY 'Pass@123' WITH GRANT OPTION

=======================================

Performance check for MySQL

show status where `variable_name` = 'Threads_connected';

show processlist
==================================

-- SET GLOBAL interactive_timeout = 1000; -- 28800 -- carefull

-- SET GLOBAL wait_timeout = 1000; -- 28800 -- carefull

SHOW STATUS WHERE `variable_name` = 'Threads_connected';

SHOW VARIABLES LIKE "max_connections"

====================================

SHOW SESSION STATUS;

show full processlist

show status where `variable_name` = 'Threads_connected';

-- kill 32042; -- carefull
-- pt-kill  -- carefull
SHOW GLOBAL STATUS;

SHOW VARIABLES LIKE "%wait%"

select concat('KILL ',id,';') from information_schema.processlist where Command='Sleep';

-- set global max_connections = 567; -- carefull

Below is to enable the Logs and set it off back
====================================

-- SET GLOBAL general_log = 'ON';

-- SHOW VARIABLES LIKE "general_log%";

-- SET GLOBAL general_log = 'OFF';

Over Clause

Without using Group by you can take the count by 
===================================
SELECT  object_id, index_id, COUNT(*) OVER ()
FROM [msdb].sys.indexes;



Count base on the Object ID
===================================
SELECT object_id, index_id, COUNT(*) OVER (PARTITION BY object_id) FROM [msdb].sys.indexes;

Good example

DECLARE @Test TABLE ( Account INTEGER, TranDate DATE, TranAmount NUMERIC(5,2)); 

 INSERT INTO @Test (Account, TranDate, TranAmount) VALUES (1, '2015-01-01', 50.00), (1, '2015-01-15', 25.00), (1, '2015-02-01', 50.00), (1, '2015-02-15', 25.00), (2, '2015-01-01', 50.00), (2, '2015-01-15', 25.00), (2, '2015-02-01', 50.00), (2, '2015-02-15', 25.00); 

 SELECT Account, TranDate, TranAmount, COUNT(*) OVER (PARTITION BY Account ORDER BY TranDate ROWS UNBOUNDED PRECEDING) AS RowNbr, COUNT(*) OVER (PARTITION BY TranDate) AS DateCount, COUNT(*) OVER (PARTITION BY Account ORDER BY TranDate ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS Last2Count FROM @Test ORDER BY Account, TranDate;

Referd by: http://www.sqlservercentral.com/articles/over+clause/132079/

If you missed any Templates in .Net


if missing templates in .net
-----------------------------------


Example: One time, i missed the Windows form project template in the .Net. So i made it like this.
(** Run as Administrator ****)
Developer command prompt --> run this under admin
then devenv /installvstemplates

Installing Nuget .Net

Via the "Package Manager Console"

    Open the console. "View" > "Other Windows" > "Package Manager Console"
    Then type the following:

    Install-Package Newtonsoft.Json

    Install-Package EntityFramework -Version 6.2.0

Dot Net Disctionary with Data Types

Dictionary<string, Type> sqlToNetTypes;

sqlToNetTypes.Add("int", typeof(int));
sqlToNetTypes.Add("varchar", typeof(string));
sqlToNetTypes.Add("datetime", typeof(DateTime));
sqlToNetTypes.Add("bit", typeof(bool));
sqlToNetTypes.Add("numeric", typeof(float));//or double or decimal as you like...

Type GetNETType(string sqlType)
{
    if(sqlToNetTypes.ContainsKey(sqlType))
    {
        return sqlToNetTypes[sqlType];
    }else
    {
        return typeof(object); //generic type
    }
}

Add/ Remove Proxy settings for Git Hub

Cannot update your git hub, because of the Proxy settings or, you need to remove the Proxy settings, do as follows
git config --global --unset http.proxy git config --global http.proxy 192.168.7.39:8080 in your command prompt

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...