Friday, March 30, 2018

T-SQL - TableSample does not always give the same number of rows

TableSample clause started with SQL Server 2015 limits the number of rows returned from a table to a sample % or sample numbers. In fact, it may not provide the specified rows of %. Also, it is not for tables with too few rows.

Here is how TableSample is defined in the MSDN site:
------------
TABLESAMPLE (10 PERCENT) /*Return a sample 10 percent of the rows of the result set. */
TABLESAMPLE (15 ROWS) /* Return a sample of 15 rows from the result set. */.
--------------
For these scenarios it cannot be applied:

Derived tables
Linked Server Tables
Tables from Table-Valued functions
Row-set functions
Open XML

This here is the syntax for TableSample clause:
----------------
TABLESAMPLE [SYSTEM] (sample_number [ PERCENT | ROWS ] )
[ REPEATABLE (repeat_seed) ]

TableSample in FROM Clause does not behave as defined in the syntax and could provide surprising results:

I queried the Northwind databases Orders table using the following syntax in SQL Server 2016 Developers edition.

SELECT * FROM Orders TableSample(10 Percent)
SELECT * FROM Orders TableSample (10)--surprisingly this does not result in error
SELECT * FROM Orders TableSample (10 ROWS)

These queries were run a number of times and the rows returned were variable from run to run and some times resulted in 0 returned rows.

Saturday, March 24, 2018

Handling Array(s) with Windows Power Shell

It is the same as a .NET array. In .NET System.Array is based on System.Object. Working with arrays in Power Shell is somewhat easier than in C#.

Assigning as Array. $ stands for a variable.


You assign the array to a variable 'flowers' as shown above. When you call the variable the array will be printed in the console as shown above.

This is same written explicitly as follows:

$flowers=@("rose", "jasmine", "lily") 
Note array elements need not be of the same type.

Writing array content to console
You can also print to the console as shown in the next. $_ is a dynamic variable storing current information.


Write-Host $_:    write current information of each element you find to the console
|                      :   Pipe command. Get the command output and pass it to another

Finding its Type
The next code shows the type of 'flowers' as an Object.


Finding an array element by its index


Add another array item to the array. 'Sun Flower' is added. Adding element using the += operator is slow, using the System.Collections.ArrayList as a New Object is faster for additions. 


Find the last elements(array items) of the array. It is zero based. 
[ .. ] is called a range operator.


Reversing an array (last becomes first and first becomes last). :: stands for static member of a class


Start with an empty array and add elements to it. @ is array operator and @() is an empty array.


Searching with wild cards in an array (in names above)

Note:
*a finds two items
*ar finds only one

Create a 2D array.

Find the second element of the second array in the above


Add a new item to the second array




UWP: SplitView XAML Control

SplitView Class in XAML provides us with two views, one for Main content and the other, a Pane that can be used for navigation.

This is the inheritance chain:

DependencyObject 
UIElement | Framework Element | Control |SplitView




An Example using Visual Studio Community 2017

You can get a basic start with the SplitView Control here.

You could replace the default 'grid' in a Blank UWP project shown here:

DefaultBlank.png

Use the following in its place:


SplitView sample.png

This is ready for build. Build and run the app in the Local Computer.
This is what you see when the app is run.


There is a Pane (the SplitView. Pane and there is a TextBlock named 'Content' in the Grid.

Now I change the OpenPanelLenth (presently 296) to, say 150 and build and run the app. What do I see?


SplitView 2

Basically you can now see more content.

In the 'Pane' you can place controls and hook up events to them to display related 'Content' in the Content (i.e., inside the 'grid' control) on the right.

Thursday, March 22, 2018

Adding an image in the Asset folder to a UWP project's page

You may need to display an image stored in the asset of your UWP project from another control's event handler.

Let us take the simple example of a button click event displaying an image stored in the project's Asset folder on the page.

At a minimum we create a UWP Blank project. Then we add a StackPanel. In the StackPanel we place two named elements, a button and an image by providing the NAME property for the controls.



We bring in an external image into the Asset Folder using:


Since we configured a click event in the XAML, this BTN_Click event code will be present in the MainPage.xaml.cs as shown.



We create an instance of Image as a new image. The source for this image has to change from System.Uri to Windows.Foundation.Uri that UWP requires and hence the conversion. 


However, code needs fixing, and there is a fix with a link. You can safely click this to modify. This includes a new using reference (using Windows.UI.Xaml.Media.Imaging) as shown. 

The this.BaseURI is now referencing the ASSETS folder's content that we added as shown.


This completes the code and the Project builds without errors. When you run it in the Local Machine as you have done with the others you see this page.

App Display

App Display after button click
It is important to note that the Visual Studio's debugging, intellisense, code completion and code hints should be used effectively as it is not possible to remember all the details of Windows.Foundation classes.



Tuesday, March 20, 2018

Python support in Visual Studio Community 2017

Yes, in a big way. Just the Intellisense support may by itself a great help.

You need to install PTVS (Python Tools for Visual Studio) to have Python support in Visual Studio (2017,2015, 2013 and earlier). In Visual Studio 2015 you need a Python Interpreter (Python 3.5 or earlier, 3.6 and above are not supported). The VS may guide you to install a Python Interpreter.

Python support is not presently available in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code.

More here:

Well, here is my personal take. I have Microsoft Visual Studio Community 2017, version 15.5.7 which has the following Python related products:

VS2017Python_1

In the installed templates I can see all of the following that are specific to Python:


VS2017Python_0
What is more. You also get other perks, if you install Visual Studio that I have installed:


VS2017Python_2

Actually, I have other Python stuff as well:










DMCA.com Protection Status