Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
-
Recent Posts
Recent Comments
Archives
Categories
Meta
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
C# is a pretty sweet language, and there are many, many, many little things that just make the code that much nicer. Have you ever been in a situation where for some reason you NEEDED to have a string/code fragment/js fragment/sql statement inline in your code because you don’t believe in resource files or stored procedures?
You could just use the @-quoting and write:
var1 = @”some text
some more text
event more text”;
There are also the programmers that ‘know of’ the @ symbol and prefix all their strings with it because it looks cool or something. Doing this without reason may actually alter the behaviour you excepted because it causes escape sequences to NOT be processed.
Eg. “c:\\my\\file.txt” could be done as @”c:\my\file.txt”
This means your \n and \t or whatever it is will also not be processed.
>
{"skillz": {"web":[{"name": "html","years": "5"},{"name": "css","years": "3"}],"database":[{"name": "sql","years": "7"}]}}
>
You can set this property in 3 ways
1.Control Level
2.Page Level
3.Application Level
Setting ClientIDMode at Control Level
Each and every server control in ASP.NET 4.0 has this property and the default value is inherit.
1.<asp:panel id="pnl" runat="server" cssclass="newStyle1"2.ClientIDMode ="Static"> </asp:panel>Setting ClientIDMode at Page Level
1.<%@ Page Language="C#" ClientIDMode ="Inherit"2.AutoEventWireup="true"3.CodeBehind="Category.aspx.cs"4.Inherits="WebApplication3.Cat" %>Setting ClientIDMode at Application Level
You need to set it at System.Web section of Web.config
1.<system.web>2.<pages clientIDMode="Predictable">3.</pages> 4.</system.web>ClientIDRowSuffix
Another interesting feature of the ClientID improvement in ASP.NET 4.0 is the ClientIDRowSuffix .This can be applied to DataBound or List controls. This is used to take control on how ID values for template controls in databound controls are generated. This requires that the ClientIDMode is set to Predictable.
1.<asp:GridView runat="server"2.ID="gvEmp" AutoGenerateColumns="False"3.ClientIDMode ="Predictable" ClientIDRowSuffix="EMPID">4.</asp:GridView>Best Practices
>
gitk $(git fsck | grep commit | cut -f3 -d' ') --since='1 week ago'
--since clause (which you can adjust to whatever you want of course; mine is just an example) limits the display to commits created recently.git fsck --unreachable | grep commit | cut -d\ -f3 |xargs git log --no-walk --merges --grep='^\(WIP on \|On \)\((no branch)\|[^ ]\+\):'
--merges but not --no-walk, and I anticipate using it a lot more in future >
There is nothing wrong with cursors except that 99.99% of the time there is a faster set based way to do accomplish what you want. That's not always true, sometimes a cursor is faster and sometimes it's the only way to do something. But those cases are very rare. And the performance hit for using cursors can be very large. And the performance hit gets worse as the amount of data increases.
Avoidance of cursons is not not just personal taste. Because of the performance problems, you should almost always avoid them.
Here is the syntax for creating the dummy table:
DECLARE @myTable AS TABLE ( [Index] INT NOT NULL IDENTITY(1, 1) ,Dbname NVARCHAR(max) ,TrackerCount INT )
>
DECLARE @db_name varchar(300)
DECLARE @Schema varchar(200)
DECLARE @tableName varchar(200)
DECLARE @InSQL varchar(200)
SET @tableName = ‘ItemDetailTypes’
SELECT @db_name = NAME FROM master.sys.SYSDATABASES ORDER BY NAME
WHILE @@ROWCOUNT > 0
BEGIN
SET @InSQL = ‘[' + @db_name + '].[' + @Schema + '].[ + @tableName + ']‘
IF OBJECT_ID(@InSQL,’U') IS NOT NULL
BEGIN
print @db_name
END
SELECT @db_name = NAME FROM master.sys.SYSDATABASES WHERE NAME < @db_name ORDER BY NAME
END
SET ROWCOUNT 0
>
Advantages of Using Git
>
DENSE_RANK
The DENSE_RANK function acts like the RANK function except that it assigns consecutive ranks:
SELECT empno,
deptno,
sal,
DENSE_RANK() OVER (PARTITION BY deptno ORDER BY sal) “rank”
FROM emp;
EMPNO DEPTNO SAL rank
———- ———- ———- ———-
7934 10 1300 1
7782 10 2450 2
7839 10 5000 3
7369 20 800 1
7876 20 1100 2
7566 20 2975 3
7788 20 3000 4
7902 20 3000 4
7900 30 950 1
7654 30 1250 2
7521 30 1250 2
7844 30 1500 3
7499 30 1600 4
7698 30 2850 5
SQL>
FIRST and LAST
The FIRST and LAST functions can be used to return the first or last value from an ordered sequence. Say we want to display the salary of each employee, along with the lowest and highest within their department we may use something like:
SELECT empno,
deptno,
sal,
MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) “Lowest”,
MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) “Highest”
FROM emp
ORDER BY deptno, sal;
EMPNO DEPTNO SAL Lowest Highest
———- ———- ———- ———- ———-
7934 10 1300 1300 5000
7782 10 2450 1300 5000
7839 10 5000 1300 5000
7369 20 800 800 3000
7876 20 1100 800 3000
7566 20 2975 800 3000
7788 20 3000 800 3000
7902 20 3000 800 3000
7900 30 950 950 2850
7654 30 1250 950 2850
7521 30 1250 950 2850
7844 30 1500 950 2850
7499 30 1600 950 2850
7698 30 2850 950 2850
SQL>
>
Both LAG and LEAD functions have the same usage, as shown below.
LAG (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)
LEAD (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)
value_expression – Can be a column or a built-in function, except for other analytic functions.
offset – The number of rows preceeding/following the current row, from which the data is to be retrieved. The default value is 1.
default – The value returned if the offset is outside the scope of the window. The default value is NULL.
Looking at the EMP table, we query the data in salary (SAL) order.
SELECT empno,
ename,
job,
sal
FROM emp
ORDER BY sal;
EMPNO ENAME JOB SAL
———- ———- ——— ———-
7369 SMITH CLERK 800
7900 JAMES CLERK 950
7876 ADAMS CLERK 1100
7521 WARD SALESMAN 1250
7654 MARTIN SALESMAN 1250
7934 MILLER CLERK 1300
7844 TURNER SALESMAN 1500
7499 ALLEN SALESMAN 1600
7782 CLARK MANAGER 2450
7698 BLAKE MANAGER 2850
7566 JONES MANAGER 2975
7788 SCOTT ANALYST 3000
7902 FORD ANALYST 3000
7839 KING PRESIDENT 5000
SQL>
LAG
The LAG function is used to access data from a previous row. The following query returns the salary from the previous row to calculate the difference between the salary of the current row and that of the previous row. Notice that the ORDER BY of the LAG function is used to order the data by salary.
SELECT empno,
ename,
job,
sal,
LAG(sal, 1, 0) OVER (ORDER BY sal) AS sal_prev,
sal – LAG(sal, 1, 0) OVER (ORDER BY sal) AS sal_diff
FROM emp;
EMPNO ENAME JOB SAL SAL_PREV SAL_DIFF
———- ———- ——— ———- ———- ———-
7369 SMITH CLERK 800 0 800
7900 JAMES CLERK 950 800 150
7876 ADAMS CLERK 1100 950 150
7521 WARD SALESMAN 1250 1100 150
7654 MARTIN SALESMAN 1250 1250 0
7934 MILLER CLERK 1300 1250 50
7844 TURNER SALESMAN 1500 1300 200
7499 ALLEN SALESMAN 1600 1500 100
7782 CLARK MANAGER 2450 1600 850
7698 BLAKE MANAGER 2850 2450 400
7566 JONES MANAGER 2975 2850 125
7788 SCOTT ANALYST 3000 2975 25
7902 FORD ANALYST 3000 3000 0
7839 KING PRESIDENT 5000 3000 2000
SQL>
LEAD
The LEAD function is used to return data from the next row. The following query returns the salary from the next row to calulate the difference between the salary of the current row and the following row.
SELECT empno,
ename,
job,
sal,
LEAD(sal, 1, 0) OVER (ORDER BY sal) AS sal_next,
LEAD(sal, 1, 0) OVER (ORDER BY sal) – sal AS sal_diff
FROM emp;
EMPNO ENAME JOB SAL SAL_NEXT SAL_DIFF
———- ———- ——— ———- ———- ———-
7369 SMITH CLERK 800 950 150
7900 JAMES CLERK 950 1100 150
7876 ADAMS CLERK 1100 1250 150
7521 WARD SALESMAN 1250 1250 0
7654 MARTIN SALESMAN 1250 1300 50
7934 MILLER CLERK 1300 1500 200
7844 TURNER SALESMAN 1500 1600 100
7499 ALLEN SALESMAN 1600 2450 850
7782 CLARK MANAGER 2450 2850 400
7698 BLAKE MANAGER 2850 2975 125
7566 JONES MANAGER 2975 3000 25
7788 SCOTT ANALYST 3000 3000 0
7902 FORD ANALYST 3000 5000 2000
7839 KING PRESIDENT 5000 0 -5000
SQL>