Skip to content

Instantly share code, notes, and snippets.

View kwestground's full-sized avatar

Kenny Westermark kwestground

View GitHub Profile
@kwestground
kwestground / NopMigrateSettings.sql
Created May 23, 2019 13:00
Migrate NopCommerce settings from one to another database
SELECT *,
CASE WHEN S1.Name IS NULL THEN 'INSERT INTO Setting VALUES ('''+S2.Name+''', '''+S2.Value+''', '+cast(S2.StoreId as varchar)+')'
ELSE 'UPDATE Setting SET [Value] = '''+S2.Value+''' WHERE [Name] = '''+S2.Name+''' ' END AS [SQL]
FROM Setting S1
FULL OUTER JOIN NopCommerceStage.dbo.Setting S2 ON S1.[Name]=S2.[Name]
WHERE ISNULL(S1.Value, '') <> ISNULL(S2.Value, '')
@kwestground
kwestground / Polr_ClearLog.sql
Last active September 12, 2019 09:12
Clear NopCommerce Log
CREATE PROCEDURE Polr_ClearLog
@Days int = 30,
@OnlyInfo bit = 1
AS
BEGIN
DELETE FROM [Log]
WHERE [CreatedOnUtc] < DATEADD(DAY, -@Days, GETDATE())
AND [LogLevelId] = CASE @OnlyInfo WHEN 1 THEN 20 ELSE [LogLevelId] END
END
GO
CREATE PROCEDURE SPLIT_COMMA(TEXT nvarchar(1000))
AS
BEGIN
declare _items nvarchar(1000) ARRAY;
declare _text nvarchar(1000);
declare _index integer;
_text := :TEXT;
_index := 1;
WHILE LOCATE(:_text,',') > 0 DO
_items[:_index] := SUBSTR_BEFORE(:_text,',');
@kwestground
kwestground / NopCommerce_DeleteSpecificationAttributeOption.sql
Created June 8, 2018 12:19
Delete SpecificationAttributeOption on SpecificationAttributeId incl. Generic Attributes
DECLARE @SpecificationAttributeId INT = 0;
DELETE FROM GenericAttribute WHERE keygroup LIKE 'ProductSpecificationAttribute'
AND EntityId IN (SELECT Id FROM Product_SpecificationAttribute_Mapping WHERE SpecificationAttributeOptionId IN (SELECT Id FROM SpecificationAttributeOption WHERE SpecificationAttributeId = @SpecificationAttributeId));
DELETE FROM GenericAttribute WHERE keygroup LIKE 'SpecificationAttributeOption' AND EntityId IN(SELECT Id FROM SpecificationAttributeOption WHERE SpecificationAttributeId = @SpecificationAttributeId);
DELETE FROM SpecificationAttributeOption WHERE SpecificationAttributeId = @SpecificationAttributeId;
DELETE FROM Product_SpecificationAttribute_Mapping WHERE SpecificationAttributeOptionId IN(SELECT Id FROM SpecificationAttributeOption WHERE SpecificationAttributeId = @SpecificationAttributeId);
@kwestground
kwestground / Install-Restart-SBOMail-Task.ps1
Last active May 16, 2018 10:56
Installs an Schedule Task to restart SBOMail service every morning at 6
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' ` -Argument 'Restart-Service -Name SBOMail'
$trigger = New-ScheduledTaskTrigger -Daily -At 6am
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Restart SBOMail" -Principal $principal
Pause
@kwestground
kwestground / Polr_UpdateLongDescrByComboSku.sql
Last active February 5, 2018 16:18
Update Description By Sku in NopCommerce
CREATE PROCEDURE Polr_UpdateLongDescrByComboSku
@Sku nvarchar(max),
@LongDescription nvarchar(max),
@LanguageId int = null
AS
BEGIN
IF @LanguageId IS NULL
BEGIN
UPDATE Product SET [FullDescription] = @LongDescription FROM Product AS p
@kwestground
kwestground / SBO_FMS_ORDR_GetPhone1.sql
Last active November 19, 2018 11:51
SBO FMS: Get Phone1 from Contact or BP
SELECT REPLACE(COALESCE(T1."Cellolar",T1."Tel1",T1."Tel2", T0."Cellular", T0."Phone1", T0."Phone2"), ' ', '') FROM "OCRD" T0
LEFT JOIN "OCPR" T1 ON T1."CardCode"=T0."CardCode" AND T1."CntctCode" = $[ORDR."CntctCode"]
WHERE T0."CardCode" = $[ORDR."CardCode"]
@kwestground
kwestground / FINDSTRING.sql
Created November 22, 2017 09:27
T-SQL. Returns the location of the specified occurrence of a string within a character expression. Same as SSIS https://docs.microsoft.com/en-us/sql/integration-services/expressions/findstring-ssis-expression
CREATE FUNCTION dbo.FINDSTRING (@character_expression nvarchar(1), @searchstring nvarchar(128), @occurance int)
RETURNS INT
AS
BEGIN
DECLARE @ret int , @pos int = CHARINDEX(@character_expression, @searchstring), @count int = 0
WHILE @pos > 0
BEGIN
SET @count = @count + 1
IF @count = @occurance
@kwestground
kwestground / QuantityToIterator.flow
Last active November 22, 2017 09:30
Create iterator from quantity input in Novacura Flow
let qtyIterator = table(line);
for i in range(0, inAntal) do
set qtyIterator = qtyIterator & [line: i];
done
return qtyIterator;
@kwestground
kwestground / NopCommerce_DeleteOrphanGenericAttribute.sql
Last active October 27, 2017 08:58
NopCommerce: Delete Orphan GenericAttribute
DELETE FROM [GenericAttribute] WHERE [Id] IN (
SELECT [T0].[Id] FROM [GenericAttribute] AS [T0]
LEFT JOIN [Customer] AS [T1] ON [T1].[Id]=[T0].[EntityId]
WHERE [T0].[KeyGroup]='Customer' AND [T1].[Id] IS NULL
)
DELETE FROM [GenericAttribute] WHERE [Id] IN (
SELECT [T0].[Id] FROM [GenericAttribute] AS [T0]
LEFT JOIN [ProductAttributeValue] AS [T1] ON [T1].[Id]=[T0].[EntityId]
WHERE [T0].[KeyGroup]='ProductAttributeValue' AND [T1].[Id] IS NULL