tsql - SSRS Parameters. Allowing "All" or "Null" -


The SSRS parameter is a pain. I want to be able to reuse the reports for many different needs by allowing users to access and make multiple optional parameters.

Therefore, if I start out of the code such as:

  select * mytable from myt, where '1 / 1/2010' and 'between myt.date' 12/31/2010 'and year (myt.date) =' 2010 'and myt.partnumber =' XYZ-123 ' 

I want those parameters to be optional so my first attempt To clear the parameters as the default:

  and (myt.partnumber = (@PartNumber) or (@PartNumber) is empty)  
< P> There are problems because if the database field in question is able to tap You will leave the record because zero is not equal faucet.

I then used this type of code:

  DECLARE @BeginDate ASDTime DECLARE @EndDate AS DATETIME DECLARE @PartNumber AS VARCHAR (25) SET @Year = ' .. All 'SET @BeginDate =' 1/1/2005 'SET @EndDate = '12 / 31/2010' SET @PartNumber = '... all' SET @Year = '..' Select all 'mytable myt From where (myt (@BeginDate) and (@EndDate) and (year (myt.date) = (@ year) or (@ year) = '..All') and (myt.partnumber = (@PartNumber) Middle date or (@PartNumber) = '..All')  

This does not work because the year (myt.date) is an integer and @ year is not.

So, these are my questions.

  1. How can I make my dates optional? Is this the best way to make default dates outside of just a practical range, so should I return all prices?
  2. What is the best way to handle empty or 'all ..' options to make my queries as readable as possible and allow my users to provide optional parameters for most data types? I like my third code block

It looks like your WHERE block Can be cured to work with non-int value. The section for the year line will look like this - not my best T-SQL, but you should point in the right direction:

  and 1 = matter = year when ' . All 'then 1 year case when the year (myt.date) = CONVERT (int, @ year) then 1 1 ELSE 0 END END  

This will give you a' value. Either match will be properly. You can do this with partnumber.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -