Pages

Friday, June 3, 2011

SSRS: Formatting a Parameter as Date/Time

This Knol covers how to convert an existing text-based parameter in Microsoft SQL Server Reporting Services to a Date/Time providing the users with a Date/Time picker to select a value rather than forcing them to enter text (i.e. 10-JAN-2010) without making a typo.


Assuming you have your report already open in Report Designer and you've just run it. The report we're going to deal with has a single parameter "INVOICE_DATE". Click "Design" at the top left:


Expand the Parameters item in the "Report Data" treeview (on the left):


Highlight "INVOICE_DATE", right-click and then select "Parameter Properties". The "Report Parameter Properties" dialog will now appear:Highlight "INVOICE_DATE", right-click and then select "Parameter Properties". The "Report Parameter Properties" dialog will now appear:


On the General tab change the Prompt to "Invoice Date: " and the Data type to "Date":On the General tab change the Prompt to "Invoice Date: " and the Data type to "Date/Time":


Click "OK".

Click "Run" the top left:


You can not see that instead of having a simple text-edit you've got a little button to click which will bring up the date picker.

SSRS: Specifying a Default Value for a Date/Time Parameter

This blog post covers how to specify a default parameter value for a Date/Time Parameter in a report written using Microsoft SQL Server Reporting Services (SSRS). You can easily modify this to specify default values for other types of parameter.


Assuming you have your report already open in Report Designer and you've just run it. The report we're going to deal with has a single parameter "INVOICE_DATE". Click "Design" at the top left:


Expand the Parameters item in the "Report Data" treeview (on the left):


Highlight "INVOICE_DATE", right-click and then select "Parameter Properties". The "Report Parameter Properties" dialog will now appear:Highlight "INVOICE_DATE", right-click and then select "Parameter Properties". The "Report Parameter Properties" dialog will now appear:


We're interested in changing the "Default Value" so select that tab:


Select the "Specify values" radio group:


Click "Add":


Then click the function button (highlighted) on the right of the new line:


Enter the expression:

=DateAdd("m", -1, DateSerial(Year(Now()), Month(Now()), 1))

(You're probably wondering where I got this from - type "reporting services first day of the month" into Google - it's the first result).

This expression will give you the first day of the PREVIOUS month. Click "OK". Click "OK". Click "OK" (you should be back to the main designer now with no additional dialogs open).

Click "Run", your report Parameter will now have a default value (and if it's the only parameter your report will now run automatically).

Thursday, June 2, 2011

Noetix: Identifying Un-used Columns For Removal

This blog post covers a description of an application (source code provided) that identifies columns which are not required (i.e. all values of the column in the view are the same) and generates a script that somone who has completed the NoetixViews Customization Certification course can include in the Generation Scripts.


The first thing to note is how this works; it opens every view doing a MIN/MAX on every column. It has been tested on a 16GB database and works fine - of course the main requirement of an application like this is to have enough TEMP tablespace in order to work. This is the reason the columns are dealt with individually rather than just opening each view and doing a MIN/MAX on every column in the view in a single hit - this was blowing out the 5GB of TEMP tablespace we had available on the test system.

The application is a simple console application:


All it does is process the views in the database using the SQL:

SELECT DISTINCT UPPER(v.VIEW_NAME) VIEWNAME
  FROM n_views v
 WHERE EXISTS
 (SELECT 'x'
          FROM all_views av
         WHERE av.OWNER = USER
           AND av.VIEW_NAME = UPPER(v.VIEW_NAME))
   AND NVL(v.OMIT_FLAG, 'N') = 'N'
   AND NVL(v.Special_Process_Code, 'X') NOT IN ('LOV', 'BASEVIEW')
   AND (UPPER(v.VIEW_NAME) = '%VIEWNAME%' OR '%VIEWNAME%' = 'ALL')
ORDER BY UPPER(v.VIEW_NAME)

This gives a list of all the views in the database. The %VIEWNAME% is replaced with the first argument on the command line (optional). If nothing is specified then it is replaced with ALL.

Views which are omitted by default are automatically excluded as are all views which are of type LOV (list of values) or BASEVIEW.

Once the list of views has been obtained then the list of columns in each view is retrieved using the SQL:

 SELECT COLUMN_NAME, DATA_TYPE, COLUMN_ID
  FROM ALL_TAB_COLUMNS ATC
 WHERE ATC.OWNER = USER
   AND ATC.TABLE_NAME = '%VIEWNAME%'
   AND ATC.COLUMN_NAME NOT LIKE 'A$%'
   AND ATC.COLUMN_NAME NOT LIKE 'Z$%'
   AND ATC.DATA_TYPE NOT IN ('ROWID', 'LONG')
   AND INSTR(ATC.COLUMN_NAME, '$') = 0

The list of  columns excludes the A$ and Z$ columns that are managed by Noetix and columns which contain a "$" symbol (flexfields) as if you want to remove these you can disable them in the e-Business Suite itself.

Once the appliction has the list of columns it looks through them building the SQL:

SELECT 1 AS IGNORE
   ,TO_CHAR(MIN()) AS MIN
   ,TO_CHAR(MAX()) AS MAX
FROM

The MIN and MAX values are then compared, if they are the same when an SQL file is created for the suppression of the field (for future reference the MIN and MAX values returned are stored in the file).

As you can imagine when accessing the GL views this query can take quite a while - for our 16GB database processing all the views in our relatively simple configuration will take about a week (running multiple processes has gotten this down to 2-3 days).

This isn't quick - but it is effective - we are removing around 3,000 columns from the views. That's 3,000 less columns in the help and for our end users to "accidentally" pick the wrong one from!

Source Code: here (Visual Studio 2010, 20kb Zip Archive)
Build Environment: VS2010 + Oracle Client

Monday, May 9, 2011

SSRS: Function ExistsInArray (Custom Report Builder Code)

A simple function for embedding in SSRS Reports that allows you to check and see if an item exists in a array of items (in either a case sensitive or insensitive way).


Here is the function;

Function ExistsInArray(ByVal SearchTerm As String, ByVal MultiValueParam As Parameter, optional ByVal CaseInsensitive as Boolean = False) As Boolean
  For i As Integer = 0 To MultiValueParam.Count - 1
    If CaseInsensitive = True Then
     If CStr(LCase(MultiValueParam.Value(i))) = LCase(SearchTerm) Then Return True
      Else
        If CStr(MultiValueParam.Value(i)) = SearchTerm Then Return True
      End If
  Next
  Return False
End Function

You pass in the SearchTerm as a string and then the multi-value parameter you wish to search through. Optionally you can make the search case insensitive by specifying True for the third parameter. The function loops through the items and when it finds one that matches it returns True, otherwise if it finds nothing it returns False.

Oracle PL/SQL: Creating A Database Link

This Knol is a quick developers guide to creating a link between two Oracle databases using TNS Information but not editing the TNSNames.ora file on the server.


It is quite often the case that it is better to link two databases together and report from one of them rather than draw together information from multiple data sources - usually because the link can be re-used more easily and as you have a requirement to re-use it then it stands to reason other people might.

The problem is that DBA's don't generally like developers making changes to the TNS file on the server - and usually this TNS file will only include information for the current database - not all the databases in your company.

Fortunately the CREATE DATABASE LINK command lets you either name a specific TNS entry OR specify the details. To create a database link called DBLINK_TEST to another oracle database which *does not* exist in the TNS file you can use;

CREATE DATABASE LINK DBLINK_TEST
       CONNECT TO
       IDENTIFIED BY
       USING '
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = 
      (PROTOCOL = TCP)
      (HOST = )
      (PORT = ))
           )
    (CONNECT_DATA = (sid = )))'

There is something to be said for not using the TNS file (especially in an Oracle EBS environment) as if you keep creating multiple clones of multiple systems the complexities of keeping the file up to date (and yes I know there are ways of automating it) might not be worth the time.

Saturday, March 5, 2011

Why is "Run as different user" not available for some programs in Windows 7?

This blog post covers one of the reasons why holding down shift and right-clicking a shortcut might not give you the "Run as different user" option - only the "Run as administrator" option.


Duplicating the Problem
This is probably one of the most annoying "features" you'll ever encounter. It's probably also one of the least clear. Luckily there's a practically guaranteed way to duplicate the problem so you can see what I mean: install iTunes.

After you have installed the software if you hold down shift and right-click the installed icon you'll notice that you don't get the "Run as different user" option. Actually if you right click it and select "Pin to taskbar" and then run iTunes you'll also notice that it creates a "new" taskbar icon whereas you'd expect it to re-use the one you'd pinned there:

Duplicate iTunes Icons
If you right-click the icon and select "Properties" you'll also notice that the Shortcut itself seems to be setup in a "strange" way:


The "Target location" and "Start in" items appear to be blank.

Fixing the problem
Find the installation directory for the software you're trying to use. For iTunes this is either "C:\Program Files (x86)\iTunes" or "C:\Program Files\iTunes" depending on the OS you are running. If you look in this directory you will see a list of files:


The one we're intersted in I've highlighted - it's the main iTunes application (you can narrow it down for your application by looking for those files with a "Type" of Application and then doing each one in turn). Right-click this file and select "Create shortcut". You will then see the message that "Window's can't create a shortcut here" and "Do you want the shortcut to be placed on the desktop instead?". Click "Yes".

Hold down shift and right-click the new shortcut on your desktop and you'll see the "Run as different user" option is now available.

Monday, February 28, 2011

SSRS: Column Duplication (Fixed Columns) on Printouts


This blog post covers implementing something like the "fixed columns" in excel which allow you to have a column (or columns) repeat on multiple pages. This only happens whey you view the report in a non-interactive way (i.e. not when viewing online).

This  blog post was put together using SQL Server 2008R2 and Report Builder 3 but it might be applicable to other versions.


Open your report in Report Builder (I'm using 3.0) and add in your duplicate column (you will need to do some sizing - for example setting up your printer format to A4 or US Letter and expanding your page 1 columns to cover the entire width of the page);

After you have added in your duplicate column select the column, right-click the heading and select "Column Visibility";

Enter the expression;

[&RenderFormat.IsInteractive]

Into the "Show or hide based on an expression" entry box.

The column will now only appear when the report is not being viewed interactively (to test you can click "Run" and then choose "Print Layout").