SSRS: CASE WHEN NULL - sql

I'm trying to import data from a table into my SQL Report Builder report.
In this particular column, the data will either be someone's name or "NULL".
I want to set my field to change NULL to "Other", but leave it how it is if it contains a name.
I know I must be close with what I have below, but I can't figure out how to get it to not alter the value if it's NOT NULL:
CASE WHEN ([Reviewed_By] IS NULL) THEN 'Other' ELSE '' END AS [Reviewed_By]
Obviously, with how it's written here, it will convert any name to a blank but I can't figure out the correct logic to get it to "skip" the line-item if it's a valid name.
Any help is appreciated!
Let me know if you need any other information.
Thanks in advance,
Cameron

you could just do ...
SELECT
ISNULL([Reviewed_By], 'Other') AS [Reviewed_By]
FROM myTable

To answer your question for the SQL side.
CASE WHEN [Reviewed_By] IS NULL THEN 'Other' ELSE [Reviewed_By] END AS [Reviewed_By]
Report builder has functionality to do this as well with expressions.
You can read more here 32716829/if-value-null-then-else-value-ssrs-expression-issues.

Related

Can I use SQL CASE statement inside GoogleSheets QUERY?

How can I (or is it possible?) use something like CASE statement in T-SQL inside QUERY in Google spreadsheet?
I want to do something like this:
=QUERY(A6:AI,"select A,(CASE WHEN D>2.5 THEN 'Yes' ELSE 'No' END),E,C,J")
I want basically a custom column with Yes/No values based on other column. Is it possible?
EDIT: To better explain, I have data in table Existing table and I would like to transform it to the Transformed table using QUERY statement:
So I need something to say: if column D is empty, print No, otherwise print Yes. This has to be in the QUERY because it's not the last column, there will be more data after column Finished. So I have this:
=QUERY(A4:D,"Select A, B, (CASE WHEN D='' THEN 'No' ELSE 'Yes' END)") - But that doesn't work
Thank you for help,
CASE & THEN are not supported in google's query language
try:
=INDEX({A6:A, IF(D6:D>2.5, "yes", "no"), E6:E, C6:C, J6:J})

PostgreSQL - Converting a string with quotes to different string using case?

So hopefully this isn't a super difficult question. I've looked around but haven't been able to find an answer. Basically I have a table in a READ-ONLY db that I'm trying to use a case statement to convert a column that stores JSON values (I think?) to something more visually pleasing.
The table shows Emails, and the Status of whether or not they're subscribed to the mailing list.
EXAMPLE HERE
Basically my query looks something like this
select
f.data as "Email",
(
case f.status
when '{"value":true}' then 'Yes'
when '{"value":false}' then 'No'
else NULL
end
) as "Subscribed"
from fields f
When I run this in my example page it works just fine when set to POSTGRES 11 but when I run it on Metabase, I get an error "ERROR: operator does not exist: json = unknown" and I'm stumped on how to proceed.
Any help here would be greatly appreciated.
That error means f.status is of type json and you're trying to compare it to a string, which doesn't work.
You can try the following instead (related documentation):
case f.status->>'value'
when 'true' then 'Yes'
when 'false' then 'No'
end
as "Subscribed"

Non mandatory parameter in pentaho report designer

I want to add a non mandatory parameter in pentaho report designer.
i.e. if the parameter is provided the same should be used in where clause else should not be used in the where clause of the query.
Please help me if this is feasible and if yes, then how to do it.
Thanks,
You can do this using the query itself.
In Postgres I use,
WHERE resourcename IN (SELECT CASE WHEN(${agent}::text = '' OR ${agent}::text IS NULL) THEN resourcename ELSE ${agent}::text END)
Here ${agent} is your parameter if they does not select or if left blank (if the display type is a 'Text Box') this query will give you the normal result else it will return what is provided in the parameter.

SQL - Conditionally joining two columns in same table into one

I am working with a table that contains two versions of stored information. To simplify it, one column contains the old description of a file run while another column contains the updated standard for displaying ran files. It gets more complicated in that the older column can have multiple standards within itself. The table:
Old Column New Column
Desc: LGX/101/rpt null
null Home
Print: LGX/234/rpt null
null Print
null Page
I need to combine the two columns into one, but I also need to delete the "Print: " and "Desc: " string from the beginning of the old column values. Any suggestions? Let me know if/when I'm forgetting something you need to know!
(I am writing in Cache SQL, but I'd just like a general approach to my problem, I can figure out the specifics past that.)
EDIT: the condition is that if substr(oldcol,1,5) = 'desc: ' then substr(oldcol,6)
else if substr(oldcol,1,6) = 'print: ' then substr(oldcol,7) etc. So as to take out the "desc: " and the "print: " to sanitize the data somewhat.
EDIT2: I want to make the table look like this:
Col
LGX/101/rpt
Home
LGX/234/rpt
Print
Page
It's difficult to understand what you are looking for exactly. Does the above represent before/after, or both columns that need combining/merging.
My guess is that COALESCE might be able to help you. It takes a bunch of parameters and returns the first non NULL.
It looks like you're wanting to grab values from new if old is NULL and old if new is null. To do that you can use a case statement in your SQL. I know CASE statements are supported by MySQL, I'm not sure if they'll help you here.
SELECT (CASE WHEN old_col IS NULL THEN new_col ELSE old_col END) as val FROM table_name
This will grab new_col if old_col is NULL, otherwise it will grab old_col.
You can remove the Print: and Desc: by using a combination of CharIndex and Substring functions. Here it goes
SELECT CASE WHEN CHARINDEX(':',COALESCE(OldCol,NewCol)) > 0 THEN
SUBSTRING(COALESCE(OldCol,NewCol),CHARINDEX(':',COALESCE(OldCol,NewCol))+1,8000)
ELSE
COALESCE(OldCol,NewCol)
END AS Newcolvalue
FROM [SchemaName].[TableName]
The Charindex gives the position of the character/string you are searching for.
So you get the position of ":" in the computed column(Coalesce part) and pass that value to the substring function. Then add +1 to the position which indicates the substring function to get the part after the ":". Now you have a string without "Desc:" and "Print:".
Hope this helps.

Can I place oracle statements inside of if else statement of sql

Problem while placing oracle query inside of the oracle if else statements
select workgroupid, maxchats,
case
when a.maxchats ='-1' then
(select propvalue from ofproperty where name = 'xmpp.live.defaults.maxchats')
else
null (1)
end as aaaa
from fpworkgroup a;
when im placing maxchats at 1 position im getting error,,
how can i resolve this....?
help me..
thanks in advance
It's hard to understand your question but it sounds like you're trying to put maxchats in place of null (1) and it gives you an error?
If that is correct, I'm guessing that the error is that fpworkgroup.maxchats and ofproperty.propvalue have different column types that do not line up. All branches of a CASE must return the same column type. You cannot, for example, return an int from one branch and return a varchar from another.
You'll have to cast one or the other so that they return the same type.