Thursday 27 March 2014

Crystal Reports for Visual Studio 2010

Tuesday 18 March 2014

SQL: MERGE statement with Trigger

Trigger Implementation

For every insert, update, or delete action specified in the MERGE statement, SQL Server fires any corresponding AFTER triggers defined on the target table, but does not guarantee on which action to fire triggers first or last. Triggers defined for the same action honor the order you specify. For more information about setting trigger firing order, see Specifying First and Last Triggers.
If the target table has an enabled INSTEAD OF trigger defined on it for an insert, update, or delete action performed by a MERGE statement, then it must have an enabled INSTEAD OF trigger for all of the actions specified in the MERGE statement.
If there are any INSTEAD OF UPDATE or INSTEAD OF DELETE triggers defined on target_table, the update or delete operations are not performed. Instead, the triggers fire and the inserted and deleted tables are populated accordingly.
If there are any INSTEAD OF INSERT triggers defined on target_table, the insert operation is not performed. Instead, the triggers fire and the inserted table is populated accordingly.

Please refer to:

Wednesday 5 March 2014

SQL - Delete Duplicated Records

WITH CTE AS(
   SELECT *,
       RN = ROW_NUMBER() OVER (PARTITION BY Code ORDER BY CreatedDate Desc)
   FROM dbo.dw_emp
)
DELETE FROM CTE WHERE RN > 1

Table dw_emp Structure
------------------------------------------------------------------------------------------------
Code Name Address CreatedDate
10001 Mark Tai Seng Street 1/12/2012
10002 Jack Jurong East St 11 12/12/2011
10001 Mark Tai Seng Street 12/5/2013

If need delete the duplicated one, and remain the one whose created date is biggest, you can use the script above.

Tuesday 4 March 2014

Excel 2007: Highlight Duplicates

Using conditional formatting, you can easily highlight duplicate values in your spreadsheet. This will make it easier to identify the duplicates so that you can remove them. To do this…

1. Select the column that is to be checked for duplicate values.
2. Go to the Ribbon and select the Home tab.
3. In the Styles section, click Conditional Formatting.
4. Select Highlight Cells Rules and click Duplicate Values.
5. In the Duplicate Values dialog box, choose the formatting you wish to use from the dropdown. The default is a light red fill with dark red text.
6. Click OK.

The background color of all values that appear more than once in the selected column will show the selected formatting.