SELECT TOP SQL alternative for Oracle databases

When querying SQL Server databases you can return the top X number of records that match the query criteria via a SQL statement similar to the following:

[sql]SELECT TOP 100 * FROM tbl_Products WHERE Prod_Desc LIKE ‘*widget*'[/sql]

However, this same SQL statement will not run against an Oracle database because there is no built-in “TOP” function.  To get around this, you can utilize the ROWNUM pseudocolumn.  Example:

[sql]SELECT * FROM tbl_Products WHERE Prod_Desc LIKE ‘%widget%’ AND ROWNUM < 101[/sql]

Query an Oracle Linked Server table from SQL Server

I have an Oracle Linked Table setup in my SQL Server database.  In order to query it’s internal tables (without needing to use OpenQuery), I use the following syntax:

[SQL]

SELECT * FROM [LinkedServerName]..[Schema].[TableName]

[/SQL]

Because the query is executed within SQL Server, you can use SQL Server-specific functions such as TOP, GetDate(), etc.  In order to pass a query directly to the Oracle table, using Oracle-specific functions/variables (TO_CHAR, SYSDATE, etc), and return the related dataset, use OpenQuery.

Populate a DataGridView with SqlDataReader

In order to display the data in a SqlDataReader object in a DataGridView control, you first need to load the data into a DataTable object. The code below is in C# and the Connection String is for a SQL Server database connection.

[csharp]
using System.Data.SqlClient;

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;

// set the connection string
con.ConnectionString = “Data Source=SqlServerName;Initial Catalog=DbName;Integrated Security=True”
con.Open();

string SQL = “SELECT * FROM tbl_Users”;

// create the SQL command
cmd = new SqlCommand(SQL, con);

// execute the SQL
dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

DataTable table = new DataTable();
table.Load(dr);

reader.Close();
reader.Dispose();
con.Close();
con.Dispose();
cmd.Dispose();
cmd = null;

// Display the data in the DataGridView control…
DataGridView1.DataSource = table;
[/csharp]

Install Windows Server 2008 R2 from USB/Thumb/Flash Drive

Format the thumb drive

  1. Format the thumb drive as Fat32

Setup the thumb drive

Open run command (Start Menu > Run), type diskpart, and hit OK.  Then type the following in sequence:
  1. list disk   (take note of the serial ### for the thumb drive)
  2. select disk 2    (assuming disk 2 is the thumb drive)
  3. clean
  4. create partition primary
  5. select partition 1
  6. active
  7. format fs=fat32  (if you don’t do this step, you won’t be able to copy any files to the thumb drive)
  8. assign
  9. exit

Copy Microsoft Windows Setup files to thumb drive

Now, open a new command window (Start Menu > Run > cmd), type the following, and hit Enter.
  • xcopy F:*.* /s/e/f G:   (assumes your source dvd is F: and your thumb drive is G:

How to add a Windows 7 computer to a Windows Server 2003 Domain

I had a bunch of problems getting this to work, but eventually found the solution; surprisingly, it was very simple.

On the machine running Windows 7 (mine was Win7 Professional), change the DNS server (in the Network Connections TCP/IP 4 section) to the IP of the Domain Server (Server 2003 machine)

Voila!

Stop the loud system beep on remote desktop sessions

Sick of the ridiculously loud system beep coming from your Remote Desktop sessions, even if you have Remote Audio Playback turned off?  If so, do the following on your local machine that you are connecting from:

  • Open Device Manager
  • View > Show Hidden Devices
  • Expand the Non-Plug and Play Drivers node
  • Right-click Beep and choose Disable

You’ll have to reboot or log-off and back in for the change to take effect.

That’s all there is to it!