Querying with multiple value parameter in SQL Server Report Builder - reportbuilder

I am basically trying to do what is asked in this question:
Passing multiple values for a single parameter in Reporting Services
but it is not working for me.
My parameter has a data type of text. I have a feeling that my parameter is being surrounded by quotes when it is inserted into my query.
Query
SELECT
AllUserData.tp_ID, Title as TestSite, tp_Title as TestCase, nvarchar6 as ItemNumber,
nvarchar7 as DefectType, nvarchar8 as Status, nvarchar9 as QuestionID,
ntext2 as Question, AllUserData.tp_Version as Version,
CONVERT(VARCHAR(10), AllUserData.tp_Modified, 111) AS DateModified
FROM
[dbTOG].[dbo].[AllUserData]
INNER JOIN
dbTOG.dbo.AllLists on dbTOG.dbo.AllUserData.tp_ListId = dbTOG.dbo.AllLists.tp_ID
INNER JOIN
dbTOG.dbo.Webs on dbTOG.dbo.AllLists.tp_WebId = dbTOG.dbo.Webs.Id
WHERE
(nvarchar8 = 'PASS' OR
nvarchar8 = 'FAIL' OR
nvarchar8 = 'N/A' OR
nvarchar8 = 'TBD' OR
nvarchar8 = 'TBRT' OR
nvarchar8 = 'FIXED')
AND Title = #TestSite
AND tp_Title IN (#TestCase)
Parameter expression for #TestCase
=Join(Parameters!TestCase.Value, ",")

This is quite late but I was struggling with pretty much the same thing. Eventually I found the answer from the link in the OT, however not the accepted one.
I changed the parameter expression to:
=SPLIT(JOIN(Parameters!<your param name>.Value,","),",")
This worked perfectly for me.

Related

Convert OOM Items.Restrict to Redemption Items.Restrict

I'm trying to convert the following working powershell OOM items.restrict:
$colMail = $olFolder.Items.Restrict("[Start] > '18/03/2022'")
$colMail = $olFolder.Items.Restrict("[Subject] = 'Test'")
RDO items.restrict
$SQL = "Subject = 'Test'" # or "where Subject = 'Test'"
$colMail = $olFolder.Items.Restrict($SQL)
$colMail = $olFolder.Items.Restrict("Subject = 'Test'")
$colMail = $olFolder.Items.Restrict("where Subject = 'Test'")
$colMail = $olFolder.Items.Restrict("Start > '2022-03-18'")
Neither of the RDO examples does return any items.
Also items.find isnt't working with RDO.
What is the correct SQL-statement in Powershell?
Thanks
Here is what the documentation says:
SQL style query specifying the condition. Can either be a WHERE part only (e.g. "LastName = 'Streblechenko' ") or a complete SQL expression with the SELECT, WHERE and ORDER BY clauses (see example).
The properties specified in the SQL query must either use the Outlook Object Model (or RDO) property name (e.g. Subject, Email1Address) or a DASL style property name (e.g. "http://schemas.microsoft.com/mapi/proptag/0x0037001E", "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/8083001E")
When a DASL property name is used, it must be enclosed in double quotes.
Including the SELECT clause allows Redemption to pre-fetch the properties from the folder contents table without opening the item resulting in a significant performance gain (see example). If you later access a property not specified in the SELECT clause, Redemption will open the item.
Including the ORDER BY clause sorts the collection in the specified order.
For example:
set Contact = Items.Restrict("SELECT Email1Address, FileAs from Folder WHERE LastName = 'PersonLastName' ORDER BY FirstName desc")

relation "table name" does not exist but it was set in FROM

I'm trying to use a sub-query in the "FROM" section but later get errors "Relation "Table name" does not exist".
I have tried to copy paste my sub-query which works, but creates really long and ugly code, as what I am sending is just a part of the whole thing which represents the same problem.
SELECT Reporter.rid , Reporter.fname , Reporter.lname
FROM Reporter , report , map , keyword , ( SELECT Reporter.rid
FROM Reporter , report , map ,
keyword
WHERE (Reporter.rid = report.rid
AND report.iid = map.iid
AND map.kword =
keyword.kword AND
keyword.subject <>
'health')
) AS nonH
WHERE (Reporter.rid NOT IN(SELECT * FROM nonH) AND Reporter.rid = report.rid)
I would expect this code to work and present me all Reporters who are not linked to anything but 'health'
Error msg is:
ERROR: relation "nonh" does not exist LINE 7: WHERE (Reporter.rid NOT
IN(SELECT * FROM nonH) AND Reporter....
You can't use a derived table in a subquery like that. You either have to reapeat the query for it:
SELECT reporter.rid,
reporter.fname,
reporter.lname
FROM reporter,
report,
map,
keyword,
(SELECT reporter.rid
FROM reporter,
report,
map,
keyword
WHERE reporter.rid = report.rid
AND report.iid = map.iid
AND map.kword = keyword.kword
AND keyword.subject <> 'health') AS nonh
WHERE reporter.rid NOT IN (SELECT reporter.rid
FROM reporter,
report,
map,
keyword
WHERE reporter.rid = report.rid
AND report.iid = map.iid
AND map.kword = keyword.kword
AND keyword.subject <> 'health')
AND reporter.rid = report.rid);
Or you can use a common table expression:
WITH
nonh
AS
(
SELECT reporter.rid
FROM reporter,
report,
map,
keyword
WHERE reporter.rid = report.rid
AND report.iid = map.iid
AND map.kword = keyword.kword
AND keyword.subject <> 'health'
)
SELECT reporter.rid,
reporter.fname,
reporter.lname
FROM reporter,
report,
map,
keyword,
nonh
WHERE reporter.rid NOT IN (SELECT rid
FROM nonh)
AND reporter.rid = report.rid);
That may fix your immediate problem. But to be honest, you query is quite a mess with all that implicit joins of tables which's columns are never used and hard to follow, let alone guess what you might be after. I recommend you rewrite it using explicit INNER JOIN/CROSS JOIN/... syntax. And question yourself what the cross joins are actually good for and if they're really needed.
there is no table called "nonH". You are creating an "nonH" alias to a subquery in your SELECT clause, but that does not create a persistent object with that name.

SELECT with substring in ON clause?

I have the following select statement in ABAP:
SELECT munic~mandt VREFER BIS AB ZZELECDATE ZZCERTDATE CONSYEAR ZDIMO ZZONE_M ZZONE_T USAGE_M USAGE_T M2MC M2MT M2RET EXEMPTMCMT EXEMPRET CHARGEMCMT
INTO corresponding fields of table GT_INSTMUNIC_F
FROM ZCI00_INSTMUNIC AS MUNIC
INNER JOIN EVER AS EV on
MUNIC~POD = EV~VREFER(9).
"where EV~BSTATUS = '14' or EV~BSTATUS = '32'.
My problem with the above statement is that does not recognize the substring/offset operation on the 'ON' clause. If i remove the '(9) then
it recognizes the field, otherwise it gives error:
Field ev~refer is unknown. It is neither in one of the specified tables
nor defined by a "DATA" statement. I have also tried doing something similar in the 'Where' clause, receiving a similar error:
LOOP AT gt_instmunic.
clear wa_gt_instmunic_f.
wa_gt_instmunic_f-mandt = gt_instmunic-mandt.
wa_gt_instmunic_f-bis = gt_instmunic-bis.
wa_gt_instmunic_f-ab = gt_instmunic-ab.
wa_gt_instmunic_f-zzelecdate = gt_instmunic-zzelecdate.
wa_gt_instmunic_f-ZZCERTDATE = gt_instmunic-ZZCERTDATE.
wa_gt_instmunic_f-CONSYEAR = gt_instmunic-CONSYEAR.
wa_gt_instmunic_f-ZDIMO = gt_instmunic-ZDIMO.
wa_gt_instmunic_f-ZZONE_M = gt_instmunic-ZZONE_M.
wa_gt_instmunic_f-ZZONE_T = gt_instmunic-ZZONE_T.
wa_gt_instmunic_f-USAGE_M = gt_instmunic-USAGE_M.
wa_gt_instmunic_f-USAGE_T = gt_instmunic-USAGE_T.
temp_pod = gt_instmunic-pod.
SELECT vrefer
FROM ever
INTO wa_gt_instmunic_f-vrefer
WHERE ( vrefer(9) LIKE temp_pod ). " PROBLEM WITH SUBSTRING
"AND ( BSTATUS = '14' OR BSTATUS = '32' ).
ENDSELECT.
WRITE: / sy-dbcnt.
WRITE: / 'wa is: ', wa_gt_instmunic_f.
WRITE: / 'wa-ever is: ', wa_gt_instmunic_f-vrefer.
APPEND wa_gt_instmunic_f TO gt_instmunic_f.
WRITE: / wa_gt_instmunic_f-vrefer.
ENDLOOP.
itab_size = lines( gt_instmunic_f ).
WRITE: / 'Internal table populated with', itab_size, ' lines'.
The basic task i want to implement is to modify a specific field on one table,
pulling values from another. They have a common field ( pod = vrefer(9) ). Thanks in advance for your time.
If you are on a late enough NetWeaver version, it works on 7.51, you can use the OpenSQL function LEFT or SUBSTRING. Your query would look something like:
SELECT munic~mandt VREFER BIS AB ZZELECDATE ZZCERTDATE CONSYEAR ZDIMO ZZONE_M ZZONE_T USAGE_M USAGE_T M2MC M2MT M2RET EXEMPTMCMT EXEMPRET CHARGEMCMT
FROM ZCI00_INSTMUNIC AS MUNIC
INNER JOIN ever AS ev
ON MUNIC~POD EQ LEFT( EV~VREFER, 9 )
INTO corresponding fields of table GT_INSTMUNIC_F.
Note that the INTO clause needs to move to the end of the command as well.
field(9) is a subset operation that is processed by the ABAP environment and can not be translated into a database-level SQL statement (at least not at the moment, but I'd be surprised if it ever will be). Your best bet is either to select the datasets separately and merge them manually (if both are approximately equally large) or pre-select one and use a FAE/IN clause.
They have a common field ( pod = vrefer(9) )
This is a wrong assumption, because they both are not fields, but a field an other thing.
If you really need to do that task through SQL, I'll suggest you to check native SQL sentences like SUBSTRING and check if you can manage to use them within an EXEC_SQL or (better) the CL_SQL* classes.

Column is not updating in postgresql

I tried to update my table like below:
$query = "select *
FROM sites s, companies c, tests t
WHERE t.test_siteid = s.site_id
AND c.company_id = s.site_companyid
AND t.test_typeid = '20' AND s.site_id = '1337'";
$queryrow = $db->query($query);
$results = $queryrow->as_array();
foreach($results as $key=>$val){
$update = "update tests set test_typeid = ? , test_testtype = ? where test_siteid = ?";
$queryrow = $db->query($update,array('10','Meter Calibration Semi Annual',$val->site_id));
}
The above code is working good. But in update query , The column test_typeid is not updated with '10'. Column test_typeid is updating with empty value. Other columns are updating good. I dont know why this column test_typeid is not updating? And the column test_typeid type is integer only. I am using postgreSql
And My table definition is:
What i did wrong with the code. Kindly advice me on this.
Thanks in advance.
First, learn to use proper JOIN syntax. Never use commas in the FROM clause; always use proper explicit JOIN syntax.
You can write the query in one statement:
update tests t
set test_typeid = '10',
test_testtype = 'Meter Calibration Semi Annual'
from sites s join
companies c
on c.company_id = s.site_companyid
where t.test_siteid = s.site_id and
t.test_typeid = 20 and s.site_id = 1337;
I assume the ids are numbers, so there is no need to use single quotes for the comparisons.

Crystal Reports filtering using optional parameters

I'm working on a report in Crystal Reports XI that allows someone to filter help desk tickets using a number of optional dynamic parameters. If I make a selection for each parameter it returns the expected results, but if I leave out any of the parameters it doesn't return anything and when I look at the SQL query it says, "No SQL Query is used because the record selection formula returns no records." I currently have the following code for Record Selection:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
)
and
If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
)
and
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
)
and
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
)
To me, this seems like it should work and if I leave out the If statement to verify the parameters have values I get an error so it seems like the HasValue is working properly. Any ideas?
Your problem stems from not explicitly handling the optional parameter configurations. It's easy to run into this problem when using if-statements in the record selection formula. Instead, explicitly handle the cases where the parameters DO and DO NOT have values. Something like this:
...
(not(hasvalue({?Group})) or {Groups.Code}={?Group})
and
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category})
and
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff} )
and
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community})
Doing it this way effectively tells CR to just ignore the parameter if is doesn't have a value, otherwise select records based on what was entered in those parameters.
The Record Selection formula indicates whether a record must be used, or not, by returning true or false. With that in mind, if some value is informed, the formula must return True if it meets some criteria. If nothing is informed on the filter, the formula must always return True.
Try something like this:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
(If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
) else
(True))
and
(If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
) else
(True))
and (
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
) else
(True))
and (
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
) else
(True))