Search code examples
sql-serverreporting-servicesssrs-2008

SSRS - Show textbox if string contains numbers


I am trying to convert the following SQL Server expression into a visibility expression in SSRS for a certain textbox that contains an error message:

select address, commonPlaceName, municipality where @Location not like '$[0-9]%'

My SSRS report lets users search for @Location, which is a combination of the address and commonPlaceName and returns a table of records.

I am trying to limit the number of rows returned based on both the character length and whether the parameter value supplied contains a number.I want to show an error message when they search for a common place or address without a number that says "Sorry your search was too broad so the number of records has been limited".

I got the length part to work by using the following:

=iif(len(Parameters!Location.Value)<=5,false,true)

But I can't figure out how to search for a number in a string

For those interested, in the SQL script, I am setting the rowcount based on a case statement that parallels the visibility options I am trying to set in SSRS.

I am still learning SSRS so any help is much appreciated!

EDIT:

Below is the SQL statement I am using to limit rowcount if that helps:

declare @top int

set @top = case when len(@Location) <= 5 then 100
            when @Location not like '%[0-9]%' then 100
            when len(@Location) >5 then 0
       end

set rowcount @top 

Solution

  • Okay I think I found a workaround for now. I ended up creating a new dataset:

    select 
    
    'LocationWithNum' = case 
                             when @Location like '%[0-9]%' then 'true'
                             else 'false'
                        end
    

    Then I changed the visibility expression of the error message textbox to the following:

    =iif(len(Parameters!Location.Value)<=5 or First(Fields!LocationWithNum.Value, "LocationWithNum") = false, false, true)
    

    So far this seems to work well. Let me know if you guys think of anything else!