Given a Commissions table with a Commission (decimal) and an employeeID primary key columns, list the top 2 commissions of each employee:
Best is to use a CTE with either the ROW_NUMBER() or RANK() partitions:
;With CTE_MyRank as (
SELECT [Commission]
,[EmployeeId]
,[CommissionID]
, ROW_NUMBER() over (partition by employeeID order by commission desc) as Rankx
FROM [Training].[dbo].[Commissions]
)
select EmployeeID, commission, Rankx from CTE_MyRank where rankx < 3 order by [EmployeeId] desc, commission desc
OR the less favorite way is to use MAX , Group By and a UNION:
Select Max([Commission]) xMax, [EmployeeId] from [Training].[dbo].[Commissions]
Group by [EmployeeId]
UNION
Select Max(Commission) xMax, [EmployeeId] from [Training].[dbo].[Commissions]
where (Commission) not in (select Max([Commission]) from [Training].[dbo].[Commissions]
Group by [EmployeeId] )
Group by [EmployeeId]
order by [EmployeeId] desc, xMAx desc
Tuesday, October 27, 2015
Monday, October 19, 2015
Get the values of all fields/properties of a C# object using reflection
using System.Reflection;
private List GetPropertyList(object obj)
{
List propertyList = new List();
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance |
BindingFlags.Public);
foreach (PropertyInfo property in properties)
{
object o = property.GetValue(obj, null);
propertyList.Add(o == null ? "" : o.ToString());
}
return propertyList;
}
private List
{
List
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance |
BindingFlags.Public);
foreach (PropertyInfo property in properties)
{
object o = property.GetValue(obj, null);
propertyList.Add(o == null ? "" : o.ToString());
}
return propertyList;
}
Link to one of the best bootstrap validators
http://1000hz.github.io/bootstrap-validator/
Also angular validations:
https://scotch.io/tutorials/angularjs-form-validation-with-ngmessages
Also angular validations:
https://scotch.io/tutorials/angularjs-form-validation-with-ngmessages
Tuesday, September 15, 2015
Open modal is shifting fixed navbar to the right
Solution:
body.modal-open {
overflow-y: scroll;
padding-right: 0 !important;
}
Reference:
https://github.com/twbs/bootstrap/issues/14040
Friday, September 11, 2015
Copying long path names in Windows - robocopy to the rescue
To copy from long path names use the robocopy command provided in Windows 8.1:
For example to mirror a folder and its sub-folders issue:
Monday, September 7, 2015
CORS, access denied issue resolved in IE11
1) Remove both server and client from Trusted sites. This solved my problems:
http://devmohd.blogspot.com/2013/09/cross-domain.html
2) If using JQuery, optionally add this for older versions of IE
jQuery.support.cors = true;
3) Optionally add this in angular config:
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
Saturday, September 5, 2015
Installing Grunt, Bower, Node.js, Ruby and Yoman
Installing Grunt, Bower, Node.js, Ruby and Yoman
Things you need
1. install NPM(https://nodejs.org/download/)
https://nodejs.org/download/release/latest/
Download and run the MSI:
node-v4.2.1-x64.msi
After running msi you could check your installation on CMD prompt:
node --version && npm --version
2. git (http://git-scm.com/download/win)
In git installation I (personally) selected:
- Use Git form Windows Command Line"
- Use Windws efault windows console
1. install NPM(https://nodejs.org/download/)
https://nodejs.org/download/release/latest/
Download and run the MSI:
node-v4.2.1-x64.msi
After running msi you could check your installation on CMD prompt:
node --version && npm --version
2. git (http://git-scm.com/download/win)
In git installation I (personally) selected:
- Use Git form Windows Command Line"
- Use Windws efault windows console
After installation you could verify the git version on CMD prompt:
git --version
3. Install ruby(http://rubyinstaller.org/)
During installation select "Add ruby executable to your path"
4) Yoman Angular generator
http://yeoman.io/codelab/setup.html
Run this:
npm install --global yo bower grunt-cli
To run AngularDemo-Master OR the RPortal Application
(By now
you should have cloned your project files from GIT into a local folder.)
1. Open a cmd prompt as admin and run the following commands in the root folder of your project (the root folder is the parent of the/app folder)
gem install ruby
gem install compass
2. Open cmd prompt as admin and run the following commands. Some of these take a long time - let them run until they return to the CMD prompt.
a. npm install
b. npm install bower
c. npm install --save-dev grunt-wiredep
d. bower install jQuery –save
1. Open a cmd prompt as admin and run the following commands in the root folder of your project (the root folder is the parent of the/app folder)
gem install ruby
gem install compass
2. Open cmd prompt as admin and run the following commands. Some of these take a long time - let them run until they return to the CMD prompt.
a. npm install
b. npm install bower
c. npm install --save-dev grunt-wiredep
d. bower install jQuery –save
(If it
asks for version of angular then choose the highest version 1.4.7 for my case)
e. grunt wiredep
f. grunt serve
e. grunt wiredep
f. grunt serve
3. In
the future in CMD prompt just type the below command from the root of your
project (the root folder is the parent of the /app folder) to bring up the localhost app:
grunt
serve
Subscribe to:
Posts (Atom)