SSRS display text when image column is null - sql

I'm trying to build a SSRS report that shows player name and their photos (if there is any). How do I display a text e.g."No image" if image column return null value (or empty)?
I've tried to do this in SSRS report itself but no luck
:
=IIF(IsNothing(Fields!PlayerImage.Value), "no image", Fields!PlayerImage.Value)
Any help is appreciated.

Assuming you get the image from a database, add a "no image" image to your database and then return that in the dataset query.
For example, if you had two tables, One with a PlayerID and Names and another with PlayerID and Image. Then you could add an entry to the image table with an ID or, say -99 and an image that just contains some text or whatever you like. Then the query would be something like...
SELECT a.PlayerID, a.PlayerName
, ISNULL(i.PlayerImage, x.PlayerImage) AS PlayerImage
FROM myPlayerTable a
LEFT JOIN myImageTable i ON a.PlayerID = i.PlayerID
CROSS JOIN (SELECT * FROM myImageTable WHERE PlayerID = -99) x
Now the report always has all the info it needs and it means you can easily change what you want to display such as an anonymous profile image that is often used.

Related

Apex Conditional Highlight with Data linked from another table

I have two separate table that store data in Apex. The main table that feeds the report is current employees. The other table I have is essentially a list of terminated employees with other information on it.
I am trying to find a way that if a name stored in both tables, that row would show up red on the report.
I put this code as an SQL Query into the report query:
select ID,
PAINT_SHOP,
"LOCKER_#",
LOCKER_LOCATION,
DEPT,
ASSOCIATE_NUMBER,
NAME__CINTAS_,
AUDIT_NOTES_,
LOCKER_TRANSFER_REQUESTED
from LOCKER_AUDIT
where (LOCKER_LOCATION = :P12_LL or :P12_LL is null)
select
NAME__CINTAS_,
case when LOCKER_TERM_LIST.NAME = 'TERMINATED' then 'salmon' else 'black' end as event_color
from Locker_Audit, LOCKER_TERM_LIST where LOCKER_AUDIT.NAME_CINTAS_ = LOCKER_TERM_LIST.NAME
*LOCKER_AUDIT --> Table for data storage of report
*LOCKER_TERM_LIST --> Table storing termed employee data
I am receiving this error:
Here is an option. Say this is your report query:
select x.*
,case when y.employee_status = 'TERMINATED' then 'salmon'
else 'black' end as event_color
from current_employees x, old_employees y
where y.employee_id = x.employee_id
Then from the content body, expand COLUMNS and look for the column you want to see in different color and click on it.
On the right frame you will see a text area called HTML Formatting.
Use some HTML there, like:
<span style="color:#EVENT_COLOR#">#YOUR_COLOURED_COLUMN#</span>
I think this would work.

Make an MS Access Report label visible based on data in the report's record source query

In MS Access, I have a report based on a query that presents a summary of a medical checkup. I would like labels for each test to be visible ONLY when those tests were performed. For example, if Glucose was performed on a patient, then the label "lblGlucose" should appear in the report, next to the result. The results currently are present in the report, the problem is when a test is not performed the label is always present. This gives the patient a feeling that the testing was not performed correctly.
To hide the labels I have tried the following approaches:
Private Sub Report_Load()
'1st approach: Lookup column [GLUCOSE] from query qrySummary if not null then set visible property of label lblGLUCOSE to True, else set property to False
IIF(IsNotNull(DLookup("[GLUCOSE]", "qrySummary")),Me!lblGLUCOSE.Visible = True,Me!lblGLUCOSE.Visible = False)
'2nd approach: If value of field [GLUCOSE_RSLT] from table tblResults make textbox txtGlucose visible. FYI: Table tblResults is the table that holds all the results of all the test performed. The query qrySummary derives from this table.
Me!txtGlucose.Visible = Not IsNull([tblResults]![GLUCOSE_RSLT])
'3rd approach: Count column [GLUCOSE], from query qrySummary and if greater than 0 then label lblBHClbl visible
End Sub
I'm still coding the 3rd approach but I'm pretty much running out of ideas and getting nowhere. For first two approaches I get field or expression not found. I don't need for all approaches to work, just one, -in fact, I'm open to other ideas on how I can accomplish the above task.
Any help would be ENORMOUSLY appreciated! Thanks a million!
I'm sharing my DB structure for better understanding
The SQL statement for the summary report is:
PARAMETERS [Forms]![frmIngresoEmpleados]![IDChequeo] Long;
SELECT TblClienteCorp.NombreEmpresa, TblClienteCorp.Direccion, tblChequeo.IDChequeo, tblChequeo.FechaMuestreo, tblChequeo.ChequeoPeriodico, qryCountGenero.*, tblEmpleadosClienteCorp.Genero, tblResultados.Aud_RSLT, tblResultados.Otos_RSLT, tblResultados.AV_RSLT, tblResultados.EKG_RSLT, tblResultados.FR_RSLT, tblResultados.TGP_RSLT, tblResultados.TGO_RSLT, tblResultados.CS_RSLT, tblResultados.ESP_RSLT, tblResultados.PB_RSLT, tblResultados.BHC_RSLT, tblResultados.Plaquetas_RSLT, tblResultados.EGO_RSLT, tblResultados.EGH_RSLT, tblResultados.VDRL_RSLT, tblResultados.Gluc_RSLT, tblResultados.Col_RSLT, tblResultados.EFEC_RSLT, tblResultados.PL_RSLT, tblResultados.Derm_RSLT, tblResultados.Isop_RSLT, tblResultados.BAAR_RSLT, tblResultados.ExFarin_RSLT, tblResultados.Lep_RSLT, tblResultados.Copro_RSLT, tblResultados.Osteo_RSLT, tblResultados.RX_RSLT, tblResultados.US_RSLT
FROM TblClienteCorp INNER JOIN ((tblChequeo INNER JOIN (tblEmpleadosClienteCorp INNER JOIN qryCountGenero ON tblEmpleadosClienteCorp.IDEmpleado = qryCountGenero.IDEmpleado) ON tblChequeo.IDChequeo = tblEmpleadosClienteCorp.IDChequeo) INNER JOIN tblResultados ON tblEmpleadosClienteCorp.IDEmpleado = tblResultados.IDEmpleados) ON TblClienteCorp.IDClienteCorp = tblChequeo.IDClienteCorp
WHERE (((tblChequeo.IDChequeo)=[Forms]![frmIngresoEmpleados]![IDChequeo]));
Within the report that is one query per test, which is:
PARAMETERS [Forms]![frmIngresoEmpleados]![IDChequeo] Long;
SELECT Count(tblResultados.IDEmpleados) AS CuentaDeIDEmpleados, tblResultados.Gluc_RSLT, tblEmpleadosClienteCorp.IDChequeo
FROM tblEmpleadosClienteCorp INNER JOIN tblResultados ON tblEmpleadosClienteCorp.IDEmpleado = tblResultados.IDEmpleados
GROUP BY tblResultados.Gluc_RSLT, tblEmpleadosClienteCorp.IDChequeo
HAVING (((tblResultados.Gluc_RSLT)="P") AND ((tblEmpleadosClienteCorp.IDChequeo)=[Forms]![frmIngresoEmpleados]![IDChequeo]));
If qrySummary has multiple patient records, need WHERE CONDITION criteria:
Me.lblGlucose.Visible = Not IsNull(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID))
However, VBA is not necessary. Calculate in textbox (or in query and bind textbox to calculated field) and set control with transparent BorderStyle. Options:
show "None" text when no data:
=Nz(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID), "None").
instead of label, use a textbox with expression:
=IIf(IsNull(DLookup("[GLUCOSE]", "qrySummary", "PatientID=" & Me!PatientID)), "", "Glucose")

Multiple entries in crystal reportviewer after adding a SQL expression field

I am using Visual Studio 2017 and I installed the latest crystal reportviewer (22)
What I want is to click a button and create a report from the customer that is selected in the datagridview and the addresses that are shown in the second datagridview.
I managed to do all that but the problem is that a few fields contain numbers which need to be converted to text. An SQL query I would use to do this would be like:
SELECT c.customer_nr, c.status, s.rename FROM CUSTOMERS c INNER JOIN SETUP s on s.id = c.status WHERE s.afk = 'STA'
In my SETUP database I have the columns ID,AFK and RENAME so if the status would be 1 it would convert to text: "ACTIVE", if status = 2 it would convert to "INACTIVE" for example.
I could do something with a formula field like this:
IF ({c.status} = 1) THEN "ACTIVE" ELSE
IF ({c.status}) = 2 THEN "INACTIVE"
but that is not good because i could add another status or change the name in the database etc.
So then I tried with an SQL expression field and I put something like this:
(
SELECT "SETUP"."RENAME" FROM SETUP
WHERE "SETUP"."AFK" = 'STA' AND "SETUP"."ID" = "CUSTOMERS"."STATUS"
)
There must be something wrong because I get the correct conversion but there is only one address in the database but I get 7 pages all with the same address. There should only be one address like I get when I remove the SQL expression field. Where does it go wrong?
* EDIT *
I found the problem. When I create a new database that contains only unique id's then it works. In my original database I have multiple times the id's 1,2,3,4,5 but with different abbreviations in column AFK. Somehow the query looks for the id value and every time it finds this id no matter the AFK value it generates an entry for the address value.
Maybe in the future I will find out how this exactly works for now I have a workaround.
Create a new table for example CrRepSta and add the following entries:
ID,AFK,RENAME
1,STA,Active
2,STA,Inactive
etc
The new query:
(
SELECT "CrRepSta"."RENAME" FROM CrRepSta
WHERE "CrRepSta"."AFK" = 'STA' AND "CrRepSta"."ID" = "CUSTOMERS"."STATUS"
)
And by the way the statement "CrRepSta"."AFK" = 'STA' is not really needed.

Using SQL to Copy specific content based on conditions of other colums

I need to use either SQL or Excel to copy the picture columns data of the other corresponding picture values for the SAME model and color when the field is NULL.
For this picture shown I need D-2 and D-4 to also say A-2.jpg instead of NULL
(It's the same A model and the color is red so copy the existing A model and red picture that's there). I need D-7 to either copy D-5 or D-6's picture value (A-4.jpg or A-5.jpg would work). So on.... If there are not particular pictures for that group (ie. model B and Black) then it can be left as NULL.
I'm trying to use group by functions and nested selects, but I am getting nowhere with this.
If you are using MS SQL Server, you can use a self join to update the table.
update r set r.picture = l.picture
from Item l
join Item r on l.model = r.model and l.color=r.color
where
l.picture is not null and
r.picture is null
Assuming your table is called "products" you might be able to do something like this:
UPDATE products p SET picture = (
SELECT picture
FROM products p2
WHERE p2.model = p.model
AND p2.color = p.model
)
WHERE p.picture IS NULL
The rules about update commands vary between different Database systems. Let us know which database you are using if the above query does not work.

How do I return distinct records in Teradata SQL when joining tables that have two entries per record?

Title is a bit of a mouthful, but essentially I have two tables, one with incident data, say, incident_data that contains things like the Incident ID, date, time, and other structured fields. The other incident_text contains the description, resolution, and other freeform text fields.
I want to search both the description and resolution fields in incident_text and join that with incident_data to get more details. They are joined by incidentno, and each incident can have two entries in incident_text, one for the description, the other for resolution.
Say this is my query:
SELECT
DISTINCT INCIDENTNO as "Incident Number",
SOME_OTHER_FIELDS ETC..,
TEXTFIELD AS "Text"
TEXTFIELDTYPE AS "Text Type"
FROM INCIDENT_DATA
INNER JOIN INCIDENT_TEXT
ON INCIDENT_DATA.INCIDENTNO=INCIDENT_TEXT.INCIDENTNO
WHERE TEXT LIKE ANY ('%THIS THING%', '%THAT THING%')
Which gives me a table like so, despite using DISTINCT
INCIDENT-1 ... FORGOT MY PASSWORD TO THIS THING ... DESCRIPTION
INCIDENT-1 ... PASSWORD RESET TO THAT THING.... RESOLUTION
If I add AND TEXTFIELDTYPE = 'DESCRIPTION' I no longer get duplicates, but I also stop searching the resolution fields, which I'd like to still do.
What I am looking for is one line per incident, with the description of the incident, while searching in both the description and resolution fields.
You're pretty close - mostly it comes down to telling SQL to treat description and resolution rows separately.
SELECT Incident_Data.incidentNo as "Incident Number",
some_other_fields etc..,
d.textField AS "Text", d.textFieldType AS "Text Type"
FROM Incident_Data
INNER JOIN Incident_Text d
ON d.incidentNo = Incident_Data.incidentNo
AND d.textFieldType = 'Description'
LEFT JOIN Incident_Text r
ON r.incidentNo = Incident_Data.incidentNo
AND r.textFieldType = 'Resolution'
AND r.textField LIKE ANY ('%THIS THING%', '%THAT THING%')
WHERE d.textField LIKE ANY ('%THIS THING%', '%THAT THING%')
OR r.incidentNo IS NOT NULL
(Not tested, please verify)
- One note - you don't use UPPER() (or LOWER(), or similar); are you certain that that casing is being used?
This is also one of the times that a WHERE clause condition can't be moved up into an INNER JOIN, as we need the rows even if the description doesn't contain the search text.