## [SQL] Can’t convert nvarchar to decimal and arithmetic overflow

Sometimes when importing datasets, or using already imported datasets in sql, the values of amounts are in nvarchar. If a cell contains a NULL value then you will not be able to sum that column. You might get the following error: “Can’t convert nvarchar to decimal and arithmetic overflow”. In this case you can create a case statement and check …

## [PHP] Return the amount of times a number occurs in an array

This exercise is about creating a function that can return the amount of times a number occurs in an array. \$zahlen1 = array(4,4,3,5,6,7,4,4); \$zahlen2 = array(1,2,6,6,3,4,5,5,5,6,7,8,6,9); \$zahlen = \$zahlen2; echo longestrow(\$zahlen); function longestrow(\$zahlen){ \$amount = 0; \$flag = 0; foreach (\$zahlen as \$value) { foreach (\$zahlen as \$value2) { if (\$value === \$value2) { \$amount++; if (\$amount > \$flag) { …

## [PHP] Ascii box generator in php with for-loop and if-statements

Exercise: Create a box in php. The corners need to be “+” plus signs. The top and bottom need to be “-” minus signs, and the walls need to be pipes “|”. An example of what the box looks like can be seen below.

## How to calculate the Median in Mysql

Since there are no built in functions to calculate the median value. You need to calculate it yourself. An important thing to know we refer twice to the country table. Once with x and once with y since we need it in our calculation.   set @median_density = (SELECT x.population/x.area from Mondial.country x, Mondial.country y GROUP BY x.population/x.area HAVING SUM(SIGN(1-SIGN(y.population/y.area-x.population/x.area)))/COUNT(*) …

## Mondial SQL Database Questions and Answers

You can find the Mondial SQL database here List all the countries that are part of Nato SELECT distinct c.name FROM Mondial.country c left join Mondial.isMember m on c.code = m.country where m.organization like ‘%nato%’; List all countries that are part of and organisation that was founded before 1960 SELECT * FROM Mondial.country c left join Mondial.isMember m on c.code …

## PHP: Basic Programming Heap Sort algorithm

Exercise from W3schools Write a PHP program to sort a list of elements using Heap sort. In computer science, heapsort (invented by J. W. J. Williams in 1964) is a comparison-based sorting algorithm. Heapsort can be thought of as an improved selection sort: like that algorithm, it divides its input into a sorted and an unsorted region, and it interactively …

## SQL: Bulkinsert data FROM CSV or TXT File

Very useful for bulk inserting data rapidly from multiple files. At the moment with this sequence you will need to change the file manually. Still very useful. Make sure you check that no columns were imported accidentally.   BULK INSERT [Clientdatabase].[dbo].[journalentries] FROM ‘C:\Users\mxk\Desktop\Clientfolder\Rawdata\Clientdata.TXT’ WITH ( fieldterminator = ‘~’, rowterminator = ‘\n’, firstrow = 2, tablock )

## SQL: How to Remove all Spaces From a Column

With the replace command you can easily replace any data in a column. In this case I am using it to remove all spaces. Useful when data looks like this “xxx xx  xxx  x”   UPDATE [Localdatabase].[dbo].[people] SET [account] = Replace([account], ‘ ‘, ”) WHERE [people_work] NOT LIKE ‘B1%’

## SQL Error: Argument data type date is invalid for argument 2 of dateadd function

You new to cast the complete column as an integer before you can use the dateadd function. That means the following code: ,dateadd(d, CONVERT(date, CASE WHEN fda.[Column1] != 0 THEN fda.[Column1] WHEN fda.[Column2] != 0 THEN bfda.[Column1] ELSE fda.[Column3] END ,114), CONVERT(date, fda.[Column3], 114)) AS [tdate] needs to be changed to the code below. Note the convert becomes cast.   …

## RHCSA Flash Cards for Exam Preparation 2019

Quizlet is one of my favourite desktop and mobile apps for creating and learning from flash cards. It is very easy to create your own flash card deck with your subject. Since quizlet is already quite popular you can profit from other people’s decks. I am preparing for my rhcsa exam in january, and I think that some of the …