COUNT(*) All DB2 Tables

tech — tags: , — rohand @ August 13, 2010 9:37 AM

Here’s a succinct way of generating SELECT COUNT(*) against all tables in a DB2 database.

SELECT 'SELECT COUNT(*) AS COUNT_' || TABLE_NAME ||
' FROM ' || TABLE_SCHEMA || '.' || TABLE_NAME
FROM sysibm.TABLES
ORDER BY TABLE_NAME 

This returns output like the following:

SELECT COUNT(*) AS COUNT_ADVISE_INDEX FROM DB2INST.ADVISE_INDEX
SELECT COUNT(*) AS COUNT_ADVISE_WORKLOAD FROM DB2INST.ADVISE_WORKLOAD

Resize an Image in C#

tech — tags: , — rohand @ June 3, 2010 11:46 AM

This function will let you resize an image in C#.

public static Bitmap Resize(Bitmap original,
                        int width, int height)
{
  Bitmap bitmap = new Bitmap(width, height);

  using (Graphics gfx = Graphics.FromImage(bitmap))
  {
    gfx.InterpolationMode
            = Drawing2D.InterpolationMode.HighQualityBicubic;
    gfx.SmoothingMode
            = Drawing2D.SmoothingMode.HighQuality;
    gfx.PixelOffsetMode
            = Drawing2D.PixelOffsetMode.HighQuality;
    gfx.CompositingQuality
            = Drawing2D.CompositingQuality.HighQuality;

    gfx.DrawImage(original, 0, 0, width, height);

    return bitmap;
  }
}

Why is mcshield.exe Running with High Priority?

tech — tags: , — rohand @ April 25, 2010 2:13 AM

After weeks of putting up with significant disk activity and system slowness, I finally noticed that the McAfee anti-virus On Access Scanner process – mcshield.exe – was running as a High Priority process in Task Manager.

The fix was simple:

  1. Open Task Manager
  2. Switch to the Processes tab
  3. Find mcshield.exe
  4. Right-click → Set Priority → Normal

Task Manager - mcshield.exe

Happy system. Happy me.

List Stored Procedures with Contents in SQL Server

tech — tags: , — rohand @ April 7, 2010 8:47 AM

I needed to get a list of all stored procedures that accessed a specific column in a table. Some stored procedures generated dynamic SQL statements so the View Dependencies feature was not guaranteed to get me the full list.

This query lets me retrieve the name and body of all stored procedures in a database. Adding the filter to look for the specific column is relatively simple.

SELECT              o.Name AS SpName, c.Text AS SpBody
FROM                syscomments c WITH (NOLOCK)
JOIN                sysobjects o WITH (NOLOCK)
ON                  c.ID = o.ID
AND                 o.Type = 'P'        -- Only stored procedures
ORDER BY            o.Name

This query is for SQL Server 2005 but should work across all versions.

Find All Rows in Table1 That Are Not in Table2 Using JOIN

tech — tags: — rohand @ February 15, 2010 1:06 PM

To find all rows that are in dbo.TABLE1 but not in dbo.TABLE2 using the SQL JOIN operator:

SELECT              COUNT(*)
FROM                dbo.TABLE1 t1 WITH (NOLOCK)
LEFT OUTER JOIN     dbo.TABLE2 t2 WITH (NOLOCK)
ON                  t1.PrimaryKey = t2.PrimaryKey
WHERE               t2.PrimaryKey IS NULL

SQL 2008 – Manage DTS Packages

tech — tags: , — rohand @ January 27, 2010 5:25 PM

I installed the SQL Server 2008 Feature Pack to get the DTS components for SQL Server Management Studio 2008. However, the IDE continued to error until I copied the following files from the SQL Server 2000 manager to the SQL 2008 Manager folders.

You need to have SQL 2000 Enterprise Manager installed on the same machine.

Copy Components into SQL Server 2005

copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\semsfc.dll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\semsfc.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\sqlgui.dll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\sqlgui.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\sqlsvc.dll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\sqlsvc.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\semsfc.rll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\Resources\1033\semsfc.rll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqlgui.rll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\Resources\1033\sqlgui.rll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqlsvc.rll" "%ProgramFiles%\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\Resources\1033\sqlsvc.rll"

Copy Components into SQL Server 2008

copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\semsfc.dll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\semsfc.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\sqlgui.dll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\sqlgui.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\sqlsvc.dll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\sqlsvc.dll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\semsfc.rll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\1033\semsfc.rll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqlgui.rll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\1033\sqlgui.rll"
copy /y "%ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqlsvc.rll" "%ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\1033\sqlsvc.rll"

Do Not .IndexOf Without Further Checks

tech — tags: , — rohand @ January 26, 2010 11:42 AM

Do not do this:

if ("A,B,C,D,E".IndexOf(key) > -1)
{
    // CODE REDACTED
}

If key is an empty string, the result is 0 and the code in the IF block is executed. This is probably not what you expected.

Google AppEngine

tech — tags: , — rohand @ January 12, 2010 6:17 PM

I have an application concept in my head and wanted to build it for Google AppEngine.

The AppEngine SDK is offered in two flavors: Python and Java. I wasn’t really sure which SDK to pick. Python has been supported since Day One – it has the most examples and the best API support. In addition, it includes the webapp framework and Django support.

I’ve picked Python as the implementation framework.

Created on a Slate PC

tech — rohand @ November 4, 2009 11:14 PM

This post was created on a Slate PC – a Motion Computing LE1600 -running Windows 7 and "typed" using the handwriting recognition very very quickly :)

I AM Impressed!

DB2 System Properties

tech — tags: — rohand @ August 18, 2009 5:16 PM

These calls will retrieve DB2 system properties.

SELECT *
FROM TABLE(SYSPROC.ENV_GET_INST_INFO()) AS Instance_Info
GO
SELECT *
FROM TABLE(SYSPROC.ENV_GET_PROD_INFO()) AS Product_Info
GO
SELECT *
FROM TABLE(SYSPROC.ENV_GET_SYS_INFO()) AS System_Info
GO

How to Create a Junction in Windows 7

tech — tags: — rohand @ August 9, 2009 5:55 PM

Create a junction in Windows 7 using the MKLINK command.

mklink /j source-path target-path

As an example, create a junction called C:\Volatile that resides on the S: drive.

mklink /j C:\Volatile S:\Volatile

Windows7-mklink

©2010 appytizers. All rights reserved.