SSRS Blank Parameters - database

I have 3 simple parameters, all which are text, and allow for multiple values as well as blank values. There are no available values or default values, as I want the users to type the value themselves. When leaving all parameters blank, no data is shown, because there are no blank values. However, I want to show all data when there is no value entered for the parameter. How can I do this?
This is what the query looks like right now
SELECT [PROGRAMNO]
,[ACCTNO]
,[CLAIMNO]
,[TOTALCHARGES]
,[TOTALPAYMENT]
,[TYPE]
FROM DATALINE
WHERE PROGRAMNO IN (#PROGRAMNO)
AND ACCTNO IN (#ACCTNO)
AND CLAIMNO IN (#CLAIMNO)

You can add an OR to allow for the NULL (or blank) value for each condition - depending on which you have allowed in the parameter.
WHERE (PROGRAMNO IN (#PROGRAMNO) OR #PROGRAMNO is null)
AND (ACCTNO IN (#ACCTNO) OR #ACCTNO IS NULL)
AND (CLAIMNO IN (#CLAIMNO) OR #CLAIMNO IS NULL)
or if you allow blank values instead:
WHERE (PROGRAMNO IN (#PROGRAMNO) OR #PROGRAMNO = '' )
AND (ACCTNO IN (#ACCTNO) OR #ACCTNO = '' )
AND (CLAIMNO IN (#CLAIMNO) OR #CLAIMNO = '' )

Multi-value parameters do not allow blank input. So you will need to add an item to your dropdown list that represents the blank value. If you are manually specifying the available values you would simply add this to the list. The value would be blank and the label could be something like "Blank" or "N/A". If you are using a query to populate the available values you will need to UNION this blank value to the other results. Either way, you'll also need to account for this in your WHERE clause in the main dataset as Hannover Fist pointed out.

Related

How do I get the first match from regexp_match?

I'd like to update a column with just the domain part of an email address.
update
users
set
email_base_domain = regexp_match(email, '(\w+\.\w+)$')
However, regexp_match returns a text[]. If email is example#foo.com the above sets email_base_domain to {foo.com}. I would like foo.com.
How do I get just the first element as text from the text[] returned by regexp_match?
Add a set of parentheses to group what you want to extract. For example:
SELECT regexp_matches(email, '(\w+)\.\w+$')
FROM users
will return {foo}, while
SELECT regexp_matches(email, '\w+\.(\w+)$')
FROM users
will return '{com}'.
Once you have a text array you can use regular array indexing to extract values from the returned text array. For example:
SELECT (regexp_matches(email, '(\w+)\.\w+$'))[1]
FROM users
returns 'foo' and
SELECT (regexp_matches(email, '\w+\.(\w+)$'))[1]
FROM users
returns 'com'.
db<>fiddle with other alternatives here

SSRS Parameters multi value problem (select all does not work)

I have a parameter 'Catégorie de vente' which contains two values 'Déchets and No Sans déchets', the problem is that when I click on select all, it just selects me the first value 'Déchets ' the other not.
Here is the parameter
And here is the request
Any heeelp pleaseee!!!!
Why selecting all does not work

SQL XML parsing using a attribute value supplied by another field in the same row

Context: I'm scraping some XML form descriptions from a Web Services table in hopes of using that name to identify what the user has inputted as response. Since this description changes for each step (row) of the process and each product I want something that can evaluate dynamically.
What I tried: The following was quite useful but it returns a dynamic attribute query result in it's own field ans using a coalesce to reduce the results as one field would lead to it's own complications: Get values from XML tags with dynamically specified data fields
Current Attempt:
I'm using the following code to generate the attribute name that I will use in the next step to query the attribute's value:
case when left([Return], 5) = '<?xml'
then lower(cast([Return] as xml).value('(/response/form/*/#name)[1]','varchar(30)'))
else ''
end as [FormRequest]
And as part of step 2 I have used the STUFF function to try and make the row-level query possible
case when len(FormRequest)>0
then stuff( ',' + 'cast([tmpFormResponse] as xml).value(''(/wrapper/#' + [FormRequest] + ')[1]'',''varchar(max)'')', 1, 1, '')
else ''
end as [FormResponse]
Instead of seeing 1 returned as my FormReponse feild value for the submit attribute (please see in yellow below) it's returning the query text -- cast([tmpFormResponse] as xml).value('(/wrapper/#submit)1','varchar(max)') -- instead (that which should be queried).
How should I action the value method so that I can dynamically strip out the response per row of XML data in tmpFormResponse based on the field value in the FormRequest field?
Thanx
You can check this out:
DECLARE #xml XML=
N'<root>
<SomeAttributes a="a" b="b" c="c"/>
<SomeAttributes a="aa" b="bb" c="cc"/>
</root>';
DECLARE #localName NVARCHAR(100)='b';
SELECT sa.value(N'(./#*[local-name()=sql:variable("#localName")])[1]','nvarchar(max)')
FROM #xml.nodes(N'/root/SomeAttributes') AS A(sa)
Ended up hacking up a solution to the problem by using PATINDEX and CHARINDEX to look for the value in the [FormRequest] field in the he tmpFormResponse field.

Updating XML value within MSSQL

replacing XML tag value within a large XML text value MSSQL.
Within MSSQL I have a column called form which is a text column with an extremely large XML. I need to find a certain tag and change the value of that sub tag within the tag from False to True.
This is what I currently have:
USE trainset;
UPDATE dbo.users
SET formxml = REPLACE(CAST(formxml as nvarchar(max)), '%<ttaycheckbox><name>cbTermsConditions</name><cargo>F</cargo></ttaycheckbox>%', '<ttaycheckbox><name>cbTermsConditions</name><cargo>T</cargo></ttaycheckbox>')
WHERE usersid = '0000GARX'
and formname ='ffOrderRpt'
and formxml LIKE ('%<ttaycheckbox><name>cbTermsConditions</name><cargo>F</cargo></ttaycheckbox>%')
It seems like it is doing the update;
However, after this when I do a select on this particular value the value of is still False rather than True.
What am I missing in there that is not causing it to update properly?
replace() doesn't support wildcards. So your where ... like finds the relevant records, but replace finds NOTHING, because it's looking for a literal %.
You can use XML modify and exist:
UPDATE users
SET formxml.modify('replace value of (/ttaycheckbox/cargo/text())[1] with "T"')
WHERE usersid = '0000GARX'
and formname ='ffOrderRpt'
and formxml.exist('/ttaycheckbox/name[text()[1] eq "cbTermsConditions"]') = 1
and formxml.exist('/ttaycheckbox/cargo[text()[1] eq "F"]') = 1

Filtering by ALL or by selected attribute

Excuse my language or SQL/Reporting wording
I am generating a report using Reporting Services where I have 2 drop down lists in order to show only by period and by category. I want it so if I select and I am shown all entries and if selected from any of the 2 drop downs then filter by those selections. I have a stored procedure which states the following on it's WHERE clause:
WHERE (dbo.PERIOD_LIST.PERIOD_DESC = #period) OR (dbo.CATEGORY.CATEGORY_DESC = #category)
However I cannot get this to work on Reporting Services/Visual Studio. I am shown ALL the entries instead of the filtered ones. I initialize #period and #category as NULL. So how can I make it so the report shows all rows when both attributes are null and still be able to filter by each or both of them?
How can I achieve this?
Edit: I used the suggestion Filip Popović gave me. If you're having this problem modify your prepared statement and make sure you refresh fields on your data sets since there's additional clauses on your prepared statement!
Note that in SQL, NULL = NULL is never evaluated to true. You can take it as NULL is not nothing it is something but unspecified. And You can't compare two unspecified values. You have to test COL1 IS NULL to get true if column has null value.
Try this:
WHERE ((dbo.PERIOD_LIST.PERIOD_DESC = #period) OR (#period IS NULL))
AND ((dbo.CATEGORY.CATEGORY_DESC = #category) OR (#category IS NULL))
Check the parameter for NULL as part of the condition:
WHERE ((#period IS NULL) OR (dbo.PERIOD_LIST.PERIOD_DESC = #period))
AND ((#category IS NULL) OR (dbo.CATEGORY.CATEGORY_DESC = #category))

Resources