Skip to content

Instantly share code, notes, and snippets.

💭
Soban-Re.

Ian Kemp IanKemp

💭
Soban-Re.
  • INVU
  • United Kingdom
View GitHub Profile
View MssqlCastToUserDefinedType.sql
-- In the year 2020, we have self-driving cars, but MSSQL doesn't have the ability to cast to user-defined types.
-- This is an extremely hacky, slow, unsafe, untested, and completely unrecommended workaround.
declare @SystemTypeId tinyint,
@MaxLength smallint
select @SystemTypeId = system_type_id, @MaxLength = max_length from sys.types where name = 'your_user_defined_type_name';
declare @TypeFullName sysname = type_name(@SystemTypeId) + (case
-- char, varchar
when @SystemTypeId in (167, 175) then '(' + cast(@MaxLength as varchar) + ')'
View Convert-ToDataTable.ps1
Function ConvertTo-DataTable { # https://powersnippets.com/convertto-pson/
[CmdletBinding()]Param( # Version 01.00.01, by iRon
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline = $true)] [PSObject[]]$Object, [HashTable]$ColumnType = @{}
)
$TypeCast = @{
Guid = 'Guid', 'String'
DateTime = 'DateTime', 'String'
DateTimeOffset = 'DateTimeOffset', 'String'
Byte = 'Byte', 'Char', 'Int16', 'Int32', 'Int64', 'UInt16', 'UInt32', 'UInt64', 'Decimal', 'Single', 'Double', 'String', 'Boolean'
SByte = 'SByte', 'Int16', 'Int32', 'Int64', 'Decimal', 'Single', 'Double', 'String', 'Boolean'
View Program.cs
using System;
using System.Net.Http;
namespace ConsoleApp18
{
class Program
{
static void Main(string[] args)
{
var client = new HttpClient();
You can’t perform that action at this time.