Saturday, March 28, 2015
Text Size

SSRS AlphaNumeric Parameter Validation

If you ever want to check the parameters submitted with a report for alpha numeric characters (so it doesn't contain symbols, punctuations, etc) then you should do this at the database level, and then get the report to complete the check:

The Plan
  1. User enters value in parameters and clicks on "View Report"
  2. Report passes parameter to dataset which gets formatted by the database
  3. Report retrieves (select) formatted parameter as a field value to use
  4. Report loads with changes based on returned value.

The Gist
  1. Add database level parameter check
  2. Add IIF in SSRS to confirm

Database Level AlphaNumeric Check
You may have better ways to do this but here are my database level checks for alphanumeric values:

  1.  -- ORACLE 
  2.  -- 0 if is alphanumeric, 1 or more if not alpha numeric. 
  3.  SELECT  
  4.  (LENGTH(TRIM(TRANSLATE(:ParameterToCheck, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'' ')))) AS NotAlphaNumeric   
  5.  FROM 
  6.  ... 
  9.  -- Transact-SQL 
  10.  -- 0 if is alphanumeric, 1 or more if not alpha numeric. 
  11.  SELECT  
  12.  PATINDEX('%[^a-zA-Z0-9]%' , @ParameterToCheckAS NotAlphaNumeric 
  13.  FROM 
  14.  ... 
  17.  -- MySQL 
  18.  -- 1 if is alphanumeric, 0 if not alpha numeric. 
  19.  SELECT 
  20.  @ParameterToCheck REGEXP '^[A-Za-z0-9]+$' AS AlphaNumeric 
  21.  FROM 
  22.  ... 


  1.  -- Using the ORACLE example 
  2.  SELECT 
  3.       Column1, 
  4.       Column2, 
  5.       (LENGTH( 
  6.            TRIM( 
  7.                 TRANSLATE( 
  8.                      :ParameterToCheck,  
  9.                      'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',  
  10.                      ' ' 
  11.                 ) 
  12.            ) 
  13.       )) AS NotAlphaNumeric   
  14.  FROM  
  15.       YourDataSetTable 
  16.  WHERE 
  17.       ThisRecord = :UserSpecifiedID 
  19.  -- where :UserSpecifiedID is one of the report parameters (Oracle local variable) 
  20.  -- where :ParameterToCheck is another of the report parameters (Oracle local variable) 
MDX Check

  1.  /*   
  2.       For Expression Value.   
  3.       Remember to apply to both ACTION and if you use color change FONT.  
  4.       Note for MySQL solution change 0 to 1. 
  5.  */ 
  6.  =IIF( 
  7.       Parameters!ParameterToCheck.Value<>"" AND Fields!NOTALPHANUMERIC.Value=0, 
  8.       "Valid", 
  9.       "Not Valid" 
  10.  ) 
If like us, you've made a report containing a link dependent on parameters submitted, we had to apply a similar IIF statement block to the Font color and the Action target as well within SSRS.
Add Comment





Help Develop!

Thank You! :c)

Connect: Google+

Visitors of the World

Latest Posts

  • Basic Android App using Google Maps and Current Location

    • Wed 25-Mar-15
      Hi Rishikesh, I use a database on a webserver with all the latitudes and longitudes of the points of ...
      Joel L.  
    • Tue 24-Mar-15
      At the starting asa I run the app. I want to show list of garages available near by my current location.
    • Mon 23-Mar-15
      Ok!! The problem is in version of the app and SDK. Thank you, resolved :lol: .
    • Sat 21-Mar-15
      It occurs with Eclipse. Close Eclipse and again open your project freshly and you will see your code ...
  • JComments 2.3.0 with ReCaptcha in Joomla 2.5.x

    • Mon 23-Mar-15
      Worked like a charm first time! :lol: Getting bored of the spam comments. This should stop them. :P