Count(*) vs Count(Column)

Difference between count(column) and count(*)


count(*) would return an extra row in the result that contains a null and the count of null values in the column.


for eg.

create table #demo(id int,id2 int)
insert #demo values(null,null)
insert #demo values(1,null)
insert #demo values(null,1)
insert #demo values(1,null)
insert #demo values(null,1)
insert #demo values(1,null)
insert #demo values(null,null)

select count(*),count(id),count(id2) from #demo

results 7 3 2

Another minor difference, between using * and a specific column, is that in the column case you can add the keyword DISTINCT, and restrict the count to distinct values

AngularJS Directive


Sharing Knowledge is always advisable


What are Directives?
Directives in AngularJS are used simplify DOM manipulation. They can modify the behavior of new and existing DOM elements, by adding custom functionality, like a datepicker or an autocomplete widget. AngularJS comes with its own set of built-in directives, as well as the ability to add your own ones.

Why are directives used in AngularJS?

Standard HTML has elements like <span>, <input>, and <button> that have fixed behavior. To make the <input> element behave like a datepicker, it takes custom CSS and JS calls from your Javascript code. AngularJS makes this easy by allowing you to wrap all this in what we call a directive. So instead of writing
<input id="datepickerElem">
and then calling
$('#datepickerElem').datepicker()

from some random place in your code, you can now instead write, directly in your HTML
<input datepicker>
or
<datepicker>
How to use directives in AngularJS?
Using directives in an AngularJS application is easy. You just need to add the directive name in whichever DOM element you want right in your HTML. For example, a datepicker Directive, depending on how it is defined, could be used as
<input datepicker>
or
<datepicker>

While declaring an AngularJS directive, the naming convention followed is camelCase. For example, we would define the name of the directive as ‘fundooDatepicker’. But when you actually use the directive in your HTML, it is the dash-separated version. That is, our widget would be ‘<fundoo-datepicker>’ and not ‘<fundooDatepicker>’


AngularJS’ in-built directives

ng-app : Initializes application.
ng-model : Binds HTML controls to application data.
ng-Controller : Attaches a controller class to view.
ng-repeat : Bind repeated data HTML elements. Its like a for loop.
ng-if : Bind HTML elements with condition.
ng-show : Used to show the HTML elements.
ng-hide : Used to hide the HTML elements.
ng-class : Used to assign CSS class.
ng-src : Used to pass the URL image etc.

Event Listeners
ng-click : Click event to bind on HTML elements.
ng-dbl-click

Mouse event listeners
ng-mousedown
ng-mouseup
ng-mouseenter
ng-mouseleave
ng-mousemove
ng-mouseover

Keyboard event listeners
ng-keydown
ng-keyup
ng-keypress
ng-change

this is not complete list. For complete one go to this link
https://docs.angularjs.org/api/ng/directive


ng-app : 

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body ng-app>
    <div>
          Here is your AJAX-powered text: <span style="color: fuchsia;">{{ txt }}</span>
            <p>
                Enter message:
                <input type="text" ng-model="txt" /></p>
    </div>
   
</body>
</html>

the output will be






HTML document is loaded into the browser, and evaluated by the browser. At this time the AngularJS JavaScript file is loaded, the angular global object is created, and your JavaScript which registers controller functions is executed.

Second, AngularJS scans through the HTML to look for AngularJS apps and views. when it find it the page is now ready.


Now if we remove the ng-app directive from body tag the output will be







ng-repeat :

<div ng-app="" ng-init="names=['Jani','Hege','Kai']">
<ul>
<li ng-repeat="x in names">
{{ x }}
</li>
</ul>
</div>

output will be :- 

Looping with ng-repeat:
  • Jani
  • Hege
  • Kai

AngularJS Expression


Sharing Knowledge is always advisable


AngularJS Expressions

AngularJS expressions can be written inside double braces: {{ expression }}.
AngularJS expressions can also be written inside a directive: ng-bind="expression".
AngularJS will resolve the expression, and return the result exactly where the expression is written.

AngularJS expressions are much like JavaScript expressions: They can contain literals, operators, and variables.
Example {{ 5 + 5 }} or {{ firstName + " " + lastName }}


<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="">
  <p>My first expression: {{ 5 + 5 }}</p>
</div>

</body>
</html>

Result will be

My first expression : 10

f you remove the ng-app directive, HTML will display the expression as it is, without solving it:

<div ng-app="" ng-init="myCol='cyan'">

<input style="background-color:{{myCol}}" ng-model="myCol" value="{{myCol}}">

</div>



ng-init is used to initialize data.

Like JavaScript expressions, AngularJS expressions can contain literals, operators, and variables.
Unlike JavaScript expressions, AngularJS expressions can be written inside HTML.
AngularJS expressions do not support conditionals, loops, and exceptions, while JavaScript expressions do.
AngularJS expressions support filters, while JavaScript expressions do not.

AngularJS arrays are like JavaScript arrays:

<div ng-app="" ng-init="points=[1,15,19,2,40]">

<p>The third result is <span ng-bind="points[2]"></span></p>

</div>

Result will be

the third result is 19

AngularJs objects are same as javascript objects

<div ng-app="" ng-init="person={firstName:'John',lastName:'Doe'}">

<p>The name is <span ng-bind="person.lastName"></span></p>

</div>

Result



The name is Doe

AngularJS Basic

Sharing Knowledge is always advisable

WHAT is AngularJS?

AngularJS is a JavaScript framework that is intended to make it easier to implement RIA web applications.

AngularJS is based on the MVC pattern (Model View Control). Therefore AngularJS separates your RIA application into models, views and controllers. The views are specified using HTML + AngularJS's own template language. The models and controllers are specified via JavaScript objects and JavaScript functions. Thus, the views are specified declaratively, as HTML normally is, and the models and controllers are specified imperatively, as JavaScript normally is.



AngularJS extends HTML with ng-directives.
The ng-app directive defines an AngularJS application.
The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
The ng-bind directive binds application data to the HTML view.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body ng-app>
    
    <div>
        <h1>
            Hello World!</h1>
        <p>
            I'm AngularJS. Here is your AJAX-powered text: <span style="color: fuchsia;"> <b><p ng-bind="txt"></p></b></h1>
            <p>
                Enter message:
                <input type="text" ng-model="txt" /></p>
    </div>
   
</body>
</html>

AngularJS starts automatically when the web page has loaded.
The ng-app directive tells AngularJS that the <body> tag is the "owner" of an AngularJS application
The ng-model directive binds the value of the input field to the application variable txt.
The ng-bind directive binds the innerHTML of the <p> element to the application variable txt.

Temp Table Vs Table Variable

1. SYNTAX
Below is the sample example of Creating a Temporary Table, Inserting records into it, retrieving the rows from it and then finally dropping the created Temporary Table.
-- Create Temporary Table
CREATE TABLE #Customer
(Id INT, Name VARCHAR(50))
--Insert Two records
INSERT INTO #Customer
VALUES(1,'Basavaraj')
INSERT INTO #Customer
VALUES(2,'Kalpana')
--Reterive the records
SELECT * FROM #Customer
--DROP Temporary Table
DROP TABLE #Customer


Below is the sample example of Declaring a Table Variable, Inserting records into it and retrieving the rows from it.
-- Create Table Variable
DECLARE @Customer TABLE
(
 Id INT,
 Name VARCHAR(50)  
)
--Insert Two records
INSERT INTO @Customer
VALUES(1,'Basavaraj')
INSERT INTO @Customer
VALUES(2,'Kalpana')
--Reterive the records
SELECT * FROM @Customer


2. MODIFYING STRUCTURE
we can use DDL statements i.e. Alter,Create,Drop
--Create Temporary Table
CREATE TABLE #Customer
(Id INT, Name VARCHAR(50))
GO
--Add Address Column
ALTER TABLE #Customer
ADD Address VARCHAR(400)
GO
--DROP Temporary Table
DROP TABLE #Customer
GO
Table Variables doesn’t support DDL statements like ALTER, CREATE, DROP etc, implies we can’t modify the structure of Table variable nor we can drop it explicitly.
3. STORAGE LOCATION
One of the most common MYTH about Temporary Table & Table Variable is that: Temporary Tables are created in TempDB and Table Variables are created In-Memory. Fact is that both are created in TempDB.
4. TRANSACTIONS
Temporary Tables support use of transactions defined by the user.
Table variables doesn’t support explicit transactions defined by the user.
5. USER DEFINED FUNCTION
Temporary Tables are not allowed in User Defined Functions.Table Variables can be used in User Defined Functions.