Remembrance Sunday – Poppies at Conisbrough Castle

In remembrance for 100 years of the Battle of the Somme, local people and businesses donated towards lighting up Conisbrough Castle.

The castle was lit up for 3 days, and raised well over £1500 for British Legion and the renovation of the local cenotaph/park.

It is estimated over 5000 people came to visit and view the display. The display even appeared on BBC News!

I took lots of pictures, here’s a selection of mine:

Gousto Meal Box – £25 off First Box

A few weeks ago I visited a country fair and got talking to a rep from Gousto. Having taken up his time, I signed up for a reduced rate trial of their boxes…

The idea behind the boxes are to have fresh “meals” delivered to your door, (well the ingredients, ready for you to make at home), each containing an exact amount of food required to create a meal. For example if the recipe requires 10g of Ginger, then you receive exactly 10g of ginger.

The meals had good instructios to follow and only took 20-40 minutes to cook.

For my first box, we had:

  • Chicken Teriyaki with Sugar Snap Peas
  • Cheesy Baked Fish with Courgette Salad
  • Mexican Pork & Black Bean Rice

Overall I was very impressed with the first box I received. Inside the box, the perishables where stored in a biodegradable bag, complete with ice blocks to keep them cool. The meals are different to what I would normally eat, but this is good in a way as it’s exploring new meals and opening my mind to new dishes.

With the discount code JONAT161748, you can receive a £25 discount off your first box and give it a go..!

£25 off first Gousto box

Convert MS SQL Query to MySQL Automatically

With a recent project, I’ve had to reproduce a table from a Microsoft SQL Database into a MySQL Database.

The table had lots of fields and would be very time consuming to write the SQL to create the table, but luckily I came across this tool to convert MSSQL to MySQL

MS SQL:

CREATE TABLE [dbo].[CRONUS UK Ltd_$Customer](
	[timestamp] [timestamp] NOT NULL,
	[No_] [varchar](20) NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Search Name] [varchar](50) NOT NULL,
	[Name 2] [varchar](50) NOT NULL,
	[Address] [varchar](50) NOT NULL,
	[Address 2] [varchar](50) NOT NULL,
	[City] [varchar](30) NOT NULL,
	[Contact] [varchar](50) NOT NULL,
	[Phone No_] [varchar](30) NOT NULL,
	[Telex No_] [varchar](20) NOT NULL,
	[Our Account No_] [varchar](20) NOT NULL,
	[Territory Code] [varchar](10) NOT NULL,
	[Global Dimension 1 Code] [varchar](20) NOT NULL,
	[Global Dimension 2 Code] [varchar](20) NOT NULL,
	[Chain Name] [varchar](10) NOT NULL,
	[Budgeted Amount] [decimal](38, 20) NOT NULL,
	[Credit Limit (LCY)] [decimal](38, 20) NOT NULL,
	[Customer Posting Group] [varchar](10) NOT NULL,
	[Currency Code] [varchar](10) NOT NULL,
	[Customer Price Group] [varchar](10) NOT NULL,
	[Language Code] [varchar](10) NOT NULL,
	[Statistics Group] [int] NOT NULL,
	[Payment Terms Code] [varchar](10) NOT NULL,
	[Fin_ Charge Terms Code] [varchar](10) NOT NULL,
	[Salesperson Code] [varchar](10) NOT NULL,
	[Shipment Method Code] [varchar](10) NOT NULL,
	[Shipping Agent Code] [varchar](10) NOT NULL,
	[Place of Export] [varchar](20) NOT NULL,
	[Invoice Disc_ Code] [varchar](20) NOT NULL,
	[Customer Disc_ Group] [varchar](10) NOT NULL,
	[Country_Region Code] [varchar](10) NOT NULL,
	[Collection Method] [varchar](20) NOT NULL,
	[Amount] [decimal](38, 20) NOT NULL,
	[Blocked] [int] NOT NULL,
	[Invoice Copies] [int] NOT NULL,
	[Last Statement No_] [int] NOT NULL,
	[Print Statements] [tinyint] NOT NULL,
	[Bill-to Customer No_] [varchar](20) NOT NULL,
	[Priority] [int] NOT NULL,
	[Payment Method Code] [varchar](10) NOT NULL,
	[Last Date Modified] [datetime] NOT NULL,
	[Application Method] [int] NOT NULL,
	[Prices Including VAT] [tinyint] NOT NULL,
	[Location Code] [varchar](10) NOT NULL,
	[Fax No_] [varchar](30) NOT NULL,
	[Telex Answer Back] [varchar](20) NOT NULL,
	[VAT Registration No_] [varchar](20) NOT NULL,
	[Combine Shipments] [tinyint] NOT NULL,
	[Gen_ Bus_ Posting Group] [varchar](10) NOT NULL,
	[Picture] [image] NULL,
	[Post Code] [varchar](20) NOT NULL,
	[County] [varchar](30) NOT NULL,
	[E-Mail] [varchar](80) NOT NULL,
	[Home Page] [varchar](80) NOT NULL,
	[Reminder Terms Code] [varchar](10) NOT NULL,
	[No_ Series] [varchar](10) NOT NULL,
	[Tax Area Code] [varchar](20) NOT NULL,
	[Tax Liable] [tinyint] NOT NULL,
	[VAT Bus_ Posting Group] [varchar](10) NOT NULL,
	[Reserve] [int] NOT NULL,
	[Block Payment Tolerance] [tinyint] NOT NULL,
	[IC Partner Code] [varchar](20) NOT NULL,
	[Prepayment %] [decimal](38, 20) NOT NULL,
	[Primary Contact No_] [varchar](20) NOT NULL,
	[Responsibility Center] [varchar](10) NOT NULL,
	[Shipping Advice] [int] NOT NULL,
	[Shipping Time] [varchar](32) NOT NULL,
	[Shipping Agent Service Code] [varchar](10) NOT NULL,
	[Service Zone Code] [varchar](10) NOT NULL,
	[Allow Line Disc_] [tinyint] NOT NULL,
	[Base Calendar Code] [varchar](10) NOT NULL,
	[Copy Sell-to Addr_ to Qte From] [int] NOT NULL,
	[Type of Supply Code] [varchar](10) NOT NULL,
	[Liq_ Payment Terms Code] [varchar](10) NOT NULL,
 CONSTRAINT [CRONUS UK Ltd_$Customer$0] PRIMARY KEY CLUSTERED 
(
	[No_] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

MySQL:

CREATE TABLE `CRONUS UK Ltd_$Customer`(
	`timestamp` `timestamp` NOT NULL,
	`No_` varchar(20) NOT NULL,
	`Name` varchar(50) NOT NULL,
	`Search Name` varchar(50) NOT NULL,
	`Name 2` varchar(50) NOT NULL,
	`Address` varchar(50) NOT NULL,
	`Address 2` varchar(50) NOT NULL,
	`City` varchar(30) NOT NULL,
	`Contact` varchar(50) NOT NULL,
	`Phone No_` varchar(30) NOT NULL,
	`Telex No_` varchar(20) NOT NULL,
	`Our Account No_` varchar(20) NOT NULL,
	`Territory Code` varchar(10) NOT NULL,
	`Global Dimension 1 Code` varchar(20) NOT NULL,
	`Global Dimension 2 Code` varchar(20) NOT NULL,
	`Chain Name` varchar(10) NOT NULL,
	`Budgeted Amount` decimal(38, 20) NOT NULL,
	`Credit Limit (LCY)` decimal(38, 20) NOT NULL,
	`Customer Posting Group` varchar(10) NOT NULL,
	`Currency Code` varchar(10) NOT NULL,
	`Customer Price Group` varchar(10) NOT NULL,
	`Language Code` varchar(10) NOT NULL,
	`Statistics Group` int NOT NULL,
	`Payment Terms Code` varchar(10) NOT NULL,
	`Fin_ Charge Terms Code` varchar(10) NOT NULL,
	`Salesperson Code` varchar(10) NOT NULL,
	`Shipment Method Code` varchar(10) NOT NULL,
	`Shipping Agent Code` varchar(10) NOT NULL,
	`Place of Export` varchar(20) NOT NULL,
	`Invoice Disc_ Code` varchar(20) NOT NULL,
	`Customer Disc_ Group` varchar(10) NOT NULL,
	`Country_Region Code` varchar(10) NOT NULL,
	`Collection Method` varchar(20) NOT NULL,
	`Amount` decimal(38, 20) NOT NULL,
	`Blocked` int NOT NULL,
	`Invoice Copies` int NOT NULL,
	`Last Statement No_` int NOT NULL,
	`Print Statements` `tinyint` NOT NULL,
	`Bill-to Customer No_` varchar(20) NOT NULL,
	`Priority` int NOT NULL,
	`Payment Method Code` varchar(10) NOT NULL,
	`Last Date Modified` datetime NOT NULL,
	`Application Method` int NOT NULL,
	`Prices Including VAT` `tinyint` NOT NULL,
	`Location Code` varchar(10) NOT NULL,
	`Fax No_` varchar(30) NOT NULL,
	`Telex Answer Back` varchar(20) NOT NULL,
	`VAT Registration No_` varchar(20) NOT NULL,
	`Combine Shipments` `tinyint` NOT NULL,
	`Gen_ Bus_ Posting Group` varchar(10) NOT NULL,
	`Picture` blob NULL,
	`Post Code` varchar(20) NOT NULL,
	`County` varchar(30) NOT NULL,
	`E-Mail` varchar(80) NOT NULL,
	`Home Page` varchar(80) NOT NULL,
	`Reminder Terms Code` varchar(10) NOT NULL,
	`No_ Series` varchar(10) NOT NULL,
	`Tax Area Code` varchar(20) NOT NULL,
	`Tax Liable` `tinyint` NOT NULL,
	`VAT Bus_ Posting Group` varchar(10) NOT NULL,
	`Reserve` int NOT NULL,
	`Block Payment Tolerance` `tinyint` NOT NULL,
	`IC Partner Code` varchar(20) NOT NULL,
	`Prepayment %` decimal(38, 20) NOT NULL,
	`Primary Contact No_` varchar(20) NOT NULL,
	`Responsibility Center` varchar(10) NOT NULL,
	`Shipping Advice` int NOT NULL,
	`Shipping Time` varchar(32) NOT NULL,
	`Shipping Agent Service Code` varchar(10) NOT NULL,
	`Service Zone Code` varchar(10) NOT NULL,
	`Allow Line Disc_` `tinyint` NOT NULL,
	`Base Calendar Code` varchar(10) NOT NULL,
	`Copy Sell-to Addr_ to Qte From` int NOT NULL,
	`Type of Supply Code` varchar(10) NOT NULL,
	`Liq_ Payment Terms Code` varchar(10) NOT NULL,
 CONSTRAINT `CRONUS UK Ltd_$Customer$0` PRIMARY KEY 
(
	`No_` ASC
)
)

;

A simple find and replace in the new SQL to correct tinyint, and then the table can be easily created in the MySQL database.

SQL Remove Trailing Decimal Places

Within a recent project, I’ve been extracting data from Microsoft Dynamics NAV using Taskcentre.

Within NAV, decimals are stored as decimal(38,20), complete will all 20 decimal places..!

Dynamics NAV 20 Decimal Places

The following SQL query is very handy at removing the un-required decimal places (but keeping the accuracy of the data)

SELECT CONVERT(DOUBLE PRECISION, 1.99990000000000000000)
	,CONVERT(DOUBLE PRECISION, 2.00000000000000000000)
	,CONVERT(DOUBLE PRECISION, 3.00005077000000000000)

The results of the above query is:

1.9999
2
3.00005077

SQL Reduce Number of Decimal Places

SQL Server – Find Last Backup Date/Time

With SQL server and 3rd party backup software, it can sometimes be difficult to tell when the last SQL backup has been taken and if the backup software has actually performed the backup or not.

There are 3 main backup types in SQL Server:

  • Full
  • Incremental
  • Transaction Log

The following SQL query will show vital statistics, including when the last backup took place for each backup type. Handy for debugging and checking backup strategies..!

This post is not going to go into the details of how each one works, or recommendations for strategies etc. There are lots of details on guides on the internet, such as this one – Microsoft Technet – Understanding SQL Backups.

 SELECT  name ,
            recovery_model_desc ,
            state_desc ,
            d AS 'Last Full Backup' ,
            i AS 'Last Differential Backup' ,
            l AS 'Last log Backup'
    FROM    ( SELECT    db.name ,
                        db.state_desc ,
                        db.recovery_model_desc ,
                        type ,
                        backup_finish_date
              FROM      master.sys.databases db
                        LEFT OUTER JOIN msdb.dbo.backupset a ON a.database_name = db.name
            ) AS Sourcetable 
        PIVOT 
            ( MAX(backup_finish_date) FOR type IN ( D, I, L ) ) AS MostRecentBackup

For example:

SQL Last Backup

TaskCentre SQL Performance – One way to improve performance

When using the “ODBC” or “OLEDB” tools in TaskCentre, it may appear that a single query is executed on the database. In actual fact from trial and error, I have identified multiple queries are being called.

For example, if you run the following query (This query identifies all Item Ledger Entries, where the timestamp is odd):

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT TOP 1000 [Item No_]
	,[Posting Date]
	,[Description]
FROM [dbo].[CRONUS UK Ltd_$Item Ledger Entry]
WHERE ([timestamp] % 2) <> 0

Notice, that the transaction isolation level is READ UNCOMMITTED. This means that the query will read the dirty data and not block other users. Also it is limited to 1000 rows.

However when the task is running, it appears that the following SQL queries are run against the database:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT TOP 1000 [Item No_]
	,[Posting Date]
	,[Description]
FROM [dbo].[CRONUS UK Ltd_$Item Ledger Entry]
WHERE ([timestamp] % 2) <> 0

and

SELECT COUNT(*)
FROM [dbo].[CRONUS UK Ltd_$Item Ledger Entry]
WHERE ([timestamp] % 2) <> 0

The first query returns the data, the 2nd query returns the number of rows.

Notice in the 2nd query, the transaction isolation level is not declared… (In this case, will cause blocking). Also the TOP statement has been removed too, meaning that all records are counted – not good especially when there is a complex filter such as the above which can be time consuming.

Solution

A solution for this is to disable the counting of the records. One way I have identified how to do this is to UNION to a table returning no rows. (As obviously you don’t want to return rows to corrupt your SQL query).

In this example:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT TOP 1000 [Item No_]
	,[Posting Date]
	,[Description]
FROM [dbo].[CRONUS UK Ltd_$Item Ledger Entry]
WHERE ([timestamp] % 2) <> 0
UNION
(SELECT NULL,NULL,NULL WHERE 1<>1)

I’ve identified that when UNION is used, Taskcentre does not count the number of records. This means that if you are using the data, the “RowCount” will return -1 instead of the actual data. If you need this for a further step (such as a decision), then you have to calculate it by looping round in VB as per this knowledgebase article.

Note and Disclaimer:
I don’t have knowledge of how the software actually works internally, so this document is only based on my experience and investigation, so is provided as-is.