ignoring the '' quotes in the Like command - db2

I have a column having values of:
Status changed from 'Closed' to 'Transferred'
Status changed from 'Resolved' to 'Transferred'
I have to get these two column values using Like command.
But if I keep like command there is 'Closed'(Single quotes) are there.
So that my query is not pulling the correct result .
can anyone please tell me how to ignore '' while using Like command?

Related

Combining rows from multiple sources in Virtual list Filemaker

I am trying to make an Excel-like 'pivot table' in Filemaker using a Virtual List as the source of the data. The issue is I want to be able to have 'categories' down the first column that aren't fixed. The field names won't work.
My current thought is to have a table with a field of the layout name and the categories, that I would combine with the rest of the data via a ExecuteSQL (or other function).
I can get it to work with two ExecuteSQL statements, one for the categories and one for the 'bulk' of the data, using text for the WHERE in the categories eSQL, then I combine them into one and I'm set.
My issue is that I'd like to be able to get the categories using a get(LayoutName) function, making the script more flexible. Whenever I use the get(LayoutName) in the WHERE line of the SQL I get a ? for the result. I have also tried putting the layout name in a field using a get(LayoutName), then using that field as in the WHERE statement, but that also returns an error.
I admit I am a bit of a newbie at this, so the problem is likely between the keyboard and the chair with a simple syntax error. I have tried a bunch of different ways with quotes, no quotes, single quotes, etc.
Here is what I am using for pulling the categories...
Substitute ( ExecuteSQL ( "SELECT Category_List
FROM Categories_VL
WHERE Layout_Name = Get(LayoutName)" ; "" ; "") ; ", " ; $$delim )
All of the field names are correct, and if I change the LayoutName to a text that matches the Layout_Name field I want, it works fine.
I apologize if I have been too wordy, but I figure more info is better than answering a bunch of questions because I forgot something!
TIA!
I am struggling to understand your question. I hope I am addressing the correct issue.
You cannot use Filemaker functions inside an SQL query. To find records where the Layout_Name field is equal to the current layout's name, your query should be:
SELECT Category_List
FROM Categories_VL
WHERE Layout_Name = ?
and then you would supply the current layout's name as an argument:
ExecuteSQL ( "SELECT Category_List FROM Categories_VL WHERE Layout_Name = ?" ; "" ; "" ; Get ( LayoutName ) )
Note that instead of substituting the default delimiter, you can specify your own field and row separators within the ExecuteSQL() function itself, for example:
ExecuteSQL ( "SELECT Category_List FROM Categories_VL WHERE Layout_Name = ?" ; $$delim ; "" ; Get ( LayoutName ) )
See: https://help.claris.com/en/pro-help/#page/FMP_Help%2Fexecutesql.html%23

DB2: Need to extract string to the left of delimitere

I have a column that looks like this:
SBN:123456=1
SBN:1234=0
SBN:12345678=5
I need to extract everything left of the equal sign ('=') for every row. I attempted using SUBSTRING this way:
SELECT COLUMN1, SUBSTR(COLUMN2,1,LOCATE('=', COLUMN2)-1) AS STUFF FROM TABLE1;
Instead of extracting the text from the string, it gave me the error "The statement was not executed because a numeric argument of a scalar function is out of range." and I can't seem to figure out why. What am I doing wrong?
I'm using DB2 11.1.4.4 on AIX, just FYI.
I found the issue. There were some NULLs in the column that the query didn't like apparently. Got rid of those and it worked fine.

How to get output of a sql with additional special characters

Long story...
I am trying to geenrate a crosstab query dynamically and run it as a psql script..
To achieve this, I want the last line of the sql to generated and appended to the top portion of the sql.
The last line of the sql is like this.... "as final_result(symbol character varying,"431" numeric,"432" numeric,"433" numeric);"
Of which, the "431", "432" etc are to be generated dynamically as these are the pivot columns and they change from time to time...
So I wrote a query to output the text as follows....
psql -c "select distinct '"'||runweek||'" numeric ,' from calendar where runweek between current_runweek()-2 and current_runweek() order by 1;" -U USER -d DBNAME > /tmp/gengen.lst
While the sql provides the output, when I run it as a script, because of the special characters (', "", ) it fails.
How should I get it working? My plan was then loop through the "lst" file and build the pivot string, and append that to the top portion of the sql and execute the script... (New to postgres, does not know , dynamic sql generation and execution etc.. but I am comfortable with UNIX scripting..)
If I could somehow get the output as
("431" numeric, "432" numeric....etc) in a single step, if there is a recommendation to achieve this, it will be greatly appreciated.....
Since you're using double quotes around the argument, double quotes inside the argument must be escaped with a backslash:
psql -c "select distinct '\"'||runweek||'\" numeric ,' from calendar where runweek between current_runweek()-2 and current_runweek() order by 1;"
Heredoc can also be used instead of -c. It accepts multi-line formatting so that makes the whole thing more readable.
(psql [arguments] <<EOF
select distinct '"'||runweek||'" numeric ,'
from calendar
where runweek between current_runweek()-2 and current_runweek()
order by 1;
EOF
) > output
By using quote_ident which is specifically meant to produce a quoted identifier from a text value, you don't even need to add the double quotes. The query could be like:
select string_agg( quote_ident(runweek::text), ',' order by runweek)
from calendar
where runweek between current_runweek()-2 and current_runweek();
which also solves the problem that your original query has a stray ',' at the end, whereas this form does not.

Accessing an object property with a "#" in the property name in Powershell?

I have an array of objects that comes back from a REST API call. The objects are "name" and "#text". Terrible names, I know, but I have no control over that. How do I get the value of both? I can get the value of #text for one entry via select -ExpandProperty `#text. I'm trying to push all the entries through the pipeline for further processing and coming up short on how to reference the #text in subsequent pipeline commands. I've tried selecting out the name and #text and renaming #text to something like 'value' but the back-tick escape used in a computed variable like below doesn't appear to work:
$bxml.properties.property|select #{n='Name';e={$_.name}},#{n='Value';e={$_.`#text}}
Anybody have suggestions as to how to code this so I can use the value of #text further down the pipeline?
Enclose the value in ' '
$bxml.properties.property|select #{n='Name';e={$_.name}},#{n='Value';e={$_.'#text'}}

list trigger no system ending with "_BI"

I want to list the trigger no system ending with "_BI" in firebird database,
but no result with this
select * from rdb$triggers
where
rdb$trigger_source is not null
and (coalesce(rdb$system_flag,0) = 0)
and (rdb$trigger_source not starting with 'CHECK' )
and (rdb$trigger_name like '%BI')
but with this syntaxs it gives me a "_bi" and "_BI0U" and "_BI0U" ending result
and (rdb$trigger_name like '%BI%')
but with this syntaxs it gives me null result
and (rdb$trigger_name like '%#_BI')
thank you beforehand
The problem is that the Firebird system tables use CHAR(31) for object names, this means that they are padded with spaces up to the declared length. As a result, use of like '%BI') will not yield results, unless BI are the 30th and 31st character.
There are several solutions
For example you can trim the name before checking
trim(rdb$trigger_name) like '%BI'
or you can require that the name is followed by at least one space
rdb$trigger_name || ' ' like '%BI %'
On a related note, if you want to check if your trigger name ends in _BI, then you should also include the underscore in your condition. And as an underscore in like is a single character matcher, you need to escape it:
trim(rdb$trigger_name) like '%\_BI' escape '\'
Alternatively you could also try to use a regular expressions, as you won't need to trim or otherwise mangle the lefthand side of the expression:
rdb$trigger_name similar to '%\_BI[[:SPACE:]]*' escape '\'