Friday 18 December 2020

Export data from stored procedure to CSV

 -- xp_cmdshell must be enabled under server security

DECLARE @cmd as varchar(4000) = 'BCP "Exec BikeStores.dbo.Test" QUERYOUT "D:\1.csv" -c -t\^, -T -S' + @@servername

EXEC master..xp_cmdshell @cmd



Friday 4 September 2020

Powerwashing the Chromebook

  • Sign out of your Chromebook
  • Press and hold Ctrl + Alt + Shift + r
  • Select Restart
  • In the box that appears, select Powerwash. Continue
  • Follow the steps that appear and sign in with your Google Account


Sunday 31 May 2020

VMWare Cannot Join to Domain - Domain in Unreachable

When trying to join to a domain in VMware Workstation, domain in unreachable. To resolve this:

1. Open cmd as an administrator
2. Execute the following command: bcdedit /set hypervisorlaunchtype off
3. Restart the host
4. Executing the following command should display the domain names: resolve-dnsname <domain-name>


Saturday 30 May 2020

Building a Windows Server Core from a Full GUI Install

The Server Core installation installs the operating system in non-GUI with minimal footprint and helps to secure the server running Hyper-V role. The benefits of using core server are:

  • Reduced attack surface
  • Reduced maintenance
  • Consume fewer hardware resources
  • Increased stability due to fewer running applications
  1. Clean install a full Windows Server
  2. Open Powershell as Administrator
  3. Execute the following commands:

    Import-Module ServerManager
    Uninstall-WindowsFeature Server-Gui-Shell-Restart
    Uninstall-WindowsfeatureServer-Gui-Mgmt-Infra-Restart

    Powershell C:\>sconfig.cmd     
    # configure the server

VMWare Unable to run a VM due to Device/Credential Guard

VMware Workstation and Device/Credential Guard are not compatible. VMware Workstation can be run after disabling Device/Credential Guard.

1. Open cmd as an administrator
2. Execute the following command: bcdedit /set hypervisorlaunchtype off
3. Restart the host

Wednesday 27 May 2020

Bring Data to HTML using D3 JS

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>HTML Data</title>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.js'></script>
</head>
<body>
  <script>
  function GetData() {
 
fetch('https://jsonplaceholder.typicode.com/todos')
  .then(response => response.json())
  .then(json=> d3.select("div")
.selectAll("p")
.data(json)
.enter()
.append("p")
.text(d => d.title));
  }
  GetData();
  </script>
 
  <h1>Hello World</h1>
  <div></div>
</body>
</html>

Tuesday 26 May 2020

Bring Data to HTML using XMLHttpRequest

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>

<script>
  function GetData() {
  var req = new XMLHttpRequest();
  req.open ('GET','https://jsonplaceholder.typicode.com/posts');
  req.onload = function () {
    var data = JSON.parse(req.responseText);
    RenderHtml (data);
}
  req.send();
}

function RenderHtml(data) {
console.log (data)
var dt = "";

for (i=0; i<data.length; i++) {
  dt += "<p>" + data[i].title + "</p>";
    }
  document.getElementById ('dataTable').innerHTML = dt;
}
</script>
</head>

<body>
<div id="dataTable">Nothing yet...</div>
<button onclick="GetData()">Get Data</button>
</body>
</html>

Tuesday 5 May 2020

Auto reconnect Blazor Serverside

Add the following method to _Host.cshtml file:

<script>
   Blazor.defaultReconnectionHandler._reconnectCallback = function(d) {
        document.location.reload(); 
   }
</script>

Tuesday 28 January 2020

SQL Get Multi Values in a Single Column

DECLARE @htmlText AS VARCHAR(MAX) = '<br/>'

SELECT STUFF
(   

(      
SELECT @htmlText + t.UserName
FROM Table t
FOR XML PATH(''), TYPE
)
.value('.[1]','nvarchar(max)'), 1, LEN(@htmlText), '' 
)

Thursday 9 January 2020

Sql Server – Split Column With Delimited String Into Multiple Columns

Method 1: To Split A Column With Delimited String Into Multiple Columns more...

Method 2: SELECT
                       PARSENAME(REPLACE ('John,Doe', ',', '.'), 2) 'First Name',
                       PARSENAME(REPLACE ('John,Doe', ',', '.'), 1) 'Last Name'

Tuesday 7 January 2020

Run Python with T-SQL on SSMS

1. Run the following commands in SSMS:
    sp_configure 'external scripts enabled'
    GO
    sp_configure 'external scripts enabled', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'external scripts enabled'
    GO

2. Restart the SQL Server Service

3. Run the following command in SSMS:
    sp_configure 'external scripts enabled'
    GO

4. Test the code:
    EXEC sp_execute_external_script
    @language = N'Python',
    @script = N'print(''Hello Python !!! from T-SQL'')'

More...

Python Clear the Interpreter Console

import os
clear = lambda: os.system('cls')
clear()


Thursday 2 January 2020

SQL Key-Value Paired Join

SELECT * FROM Tabe1 u
JOIN (
(123, 'peter6@gmail.com', 3),
(555, 'jbrown@gmail.com', 4),
(946, 'jdoe12@gmail.com', 1)
) v(EmployeeId, Email, Department)
ON (
v.Email = u.Email
and v.EmployeeId = u.EmployeeId
)


Upgrade Windows 11 Home to Windows 11 Pro

Disable internet connection (Wi-Fi, Internet, etc.) Change the product key using the following Generic product key:                     VK7J...