Monday, August 23, 2010

USING ROW_NUMBER FUNCTION IN SQL QUERY

ROW_NUMBER is used to query the row number. It's very useful when need to get the sequence number of an ordered query.
Here's the example of query to use it.

Table 'TClass'




Give row number from the most to least Num_Attendee:

Query:
SELECT ROW_NUMBER() OVER (ORDER BY Num_Attendee desc) AS Row_Num, * FROM TClass

Result:




Give row number for each Class from the most to least Num_Attendee in a class:

Query:
SELECT ROW_NUMBER() OVER (PARTITION BY CLASS ORDER BY Num_Attendee desc) AS Row_Num, * FROM TClass

Result:




Get the most Num_attendee of each class:

Query:
SELECT Class, Num_attendee FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY CLASS ORDER BY Num_Attendee desc) AS Row_Num, * FROM TClass
) x
WHERE x.Row_Num=1

Result:

Tuesday, July 13, 2010

How to Remove All Hyperlinks in Word or Excel

Here's the step by step how to remove all hyperlinks in your excel or Word file:

1. Open the word/ excel file
2. Hit [Alt]+[F11] to open the Visual Basic Editor
3. Go to menu [Insert]>[Module]
4. Copy and paste the code below:

Ms. Word:
Sub RemoveHyperlinks()
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldHyperlink Then
oField.Unlink
End If
Next
Set oField = Nothing
End Sub

Ms. Excel:
Sub RemoveHyperlinks()
'Remove all hyperlinks from the active sheet
ActiveSheet.Hyperlinks.Delete
End Sub

5. And then click [File]>[Close]
6. On Word/Excel file go to [View]>[Macros]>[View Macros]
7. Run “RemoveAllHyperlinks”
8. Now all hyperlinks are removed successfully

Note: I'm using Office 2007

Friday, April 30, 2010

Microsoft Office 2007 to PDF

In Ms Office 2007, there's add-in allows you to export and save to the PDF and XPS formats.

The installer called SaveAsPDFandXPS.exe, can be found by searching in your desired search engine.

What to do is just click on the installer and follow the instructions to complete the installation.
You'll see the add-in in the Ms office in the Save As sections.