Advertisements

Get Row Number in MySQL


SQL Server

To return a row number with record we have ROW_NUMBER() in SQL which  returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.

Syntax:

ROW_NUMBER ( )
OVER ( [ PARTITION BY value_expression , … [ n ] ] order_by_clause )

MY SQL

Here I am explaining how to return row number in my sql

For Example we have following table

CREATE TABLE tblSales(
  id     INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  fruit  VARCHAR(32),
  amount DECIMAL
);

INSERT INTO tblSales
VALUES 
(NULL, 'apple', 12.75), 
(NULL, 'orange', 1.89), 
(NULL, 'pear', 19.23),
(NULL, 'banana', 4.25), 
(NULL, 'cherry', 123.75), 
(NULL, 'plum', 23.15);
SELECT fruit, amount FROM tblSales ORDER BY amount DESC;

If we run this query it will result like
+--------+--------+
| fruit  | amount |
+--------+--------+
| cherry |    124 |
| plum   |     23 |
| pear   |     19 |
| apple  |     13 |
| banana |      4 |
| orange |      2 |
+--------+--------+


Now here is the query with ranking

SET @rank=0;
SELECT @rank:=@rank+1 AS rank, fruit, amount FROM tblSales
 ORDER BY amount DESC;

+------+--------+--------+
| rank | fruit  | amount |
+------+--------+--------+
|    1 | cherry |    124 |
|    2 | plum   |     23 |
|    3 | pear   |     19 |
|    4 | apple  |     13 |
|    5 | banana |      4 |
|    6 | orange |      2 |
+------+--------+--------+
Hope it helps!
Advertisements

Create duplicate row in AngularJS


Hello Friends here I am explaining an example of how to add duplicate row in AngularJS

Please check below link for complete example

https://jsfiddle.net/rahulgbhatia/06nda8jo/

Hope it helps !

 

 

Modify Collection while Iterating C#

May 10, 2017 1 comment

The general rule is that you can’t modify a collection/array/list while iterating over it.

If you are trying to modify loop while iterating you will get following error message

List strList = new List();

strList.Add(“1”);
strList.Add(“2”);
strList.Add(“3”);
strList.Add(“4”);

foreach(string str in strList)
{
strList.Add(“test”);
}

Error:

System.InvalidOperationException: Collection was modified; 
enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Rextester.Program.Main(String[] args)

Here is the simple solution

int listLength = strList.Count();

for(int i=0; i<listLength; i++)
{

//Add New Element
if(i == 0)//Some codition when you want to add new element to list/array
{
listLength++;
strList.Add(“5”);
}

Console.WriteLine(strList[i]);
}

Hope it helps !

Send Email from a Static HTML

April 29, 2017 9 comments

Send an email without back-end/server side code.

There are many solutions available for sending an email here I am explaining steps to sending an email from html page using Google Apps mail.

1. Make a Copy of the Sample Spreadsheet.

Sample: https://docs.google.com/spreadsheets/d/1Bn4m6iA_Xch1zzhNvo_6CoQWqOAgwwkOWJKC-phHx2Q/

1

2.Open the Script Editor

Open the Script editor… by clicking “Tools” > “Script editor…

3

3. Set the TO_ADDRESS in the Script

4

4. Save a New Version of your Script

Goto File-> Manager Version option to set Version

5. Publish the Updated Script as a Web App

Goto menu Publish-> Deploy as Web app option to publish

Select the latest project version to deploy:

7

6. Authorize the Script to Send Emails

Click Continue to authorize this app

8

Copy the web app URL to your clip board / note pad. Then Click “OK”.

10

7. Create your basic HTML Form

11

8. Open the HTML Form (page) in your Browser

Fill in some sample data in the HTML Form:

12

Submit the form. You should see a confirmation that it was sent like

{“result”:”success”,”data”:”{\”color\”:[\”\”],\”name\”:[\”Rahul\”],\”message\”:[\”This is test \”],\”email\”:[\”rahulgbhatia@live.com\”]}”}

Alternate solution : Use Ajax to submit the form

Hope this help !

Background Reading

 

Set focus on textbox

November 16, 2016 Leave a comment

Using Jquery

$(function() {
  $("#Box1").focus();
});

Using Javascript
window.onload = function() {
  document.getElementById("Box1").focus();
};

HTML5 

http://www.codeproject.com/members/flair/8524963

Categories: ASP.NET, Code Project Tags: , , ,

Disable click outside of bootstrap model area to close modal


Problem :You can close the modal by clicking on the background. Is there anyway to disable this feature? On specific modals only?

Solution :

There is option called backdrop. Passing this option with value 'static' will prevent closing the modal.
Also can pass {keyboard: false} to prevent closing the modal by pressing Esc.

[1] If you opening the modal by js use:
$
('#myModal').modal({backdrop: 'static', keyboard: false})

[2] If you are using data attributes, use:
<button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
</button>`

 

 

AngularJS: Get selected Text and Value of HTML Select DropDownList using ng-change


The below HTML Markup consists of an HTML DIV to which ng-app and ng-controller AngularJS directives have been assigned.

The HTML DIV consists of an HTML Select DropDownList which will be populated from JSON array using ng-options directive.

The HTML Select DropDownList has been assigned ng-change directive. When an option is selected in HTML Select DropDownList then the GetValue function of the Controller gets called.
Inside the function, first the selected Value is fetched from the ng-model attribute and the selected Text is fetched from the JSON array using jQuery grep function.
Finally the selected Text and Value is displayed using JavaScript alert message box.

2016-06-21_1554