Replace value in multiple strings without charindex - sql

so This is a sample of my DB Values
UPDATE page p SET p.content = REPLACE(p.content, SUBSTRING(p.content, CHARINDEX('php?id=', p.content) +1), CONCAT('php?id=',p.course)) WHERE p.content LIKE '%php?id=%' AND p.content NOT LIKE CONCAT('%','php?id=',p.course,'%');
I'm Trying to only get the text after php?id= which is a number and change it to the correct number which is the course column
so for example the first value should be changed to
4|Enjoy your training!<a href="*/view.php?id=4">
Unfortunately charindex keeps giving me an Error
Any Help on how to Make this thing work without charindex as i Believe our server does not support this function
UPDATE: Charindex didnt exist in mysql so i had to use LOCATE fuction instead. Also i wasnt using the root password for the whole server, just the root password for the db
Thanks for the heads up!
Now just need the query to correctly update... as it removes just everything after <a href etc etc and doesnt replace

Related

PostgreSQL: How to extract text from a particular letter?

I'm practicing exercises with SQL and I've got a problem I couldn't resolve yet.
I have a table with a column named: **'email' ** and I want to extract just the Domain of each mail. Then I was thinking to extract since '#' to get that information.
But idk how to do it, was trying with SUBSTRING, but that didn't work because that's about position, and each mail has different size.
I attach a screenshot about the table's composition (does not contain real information). Thank u so much :)
I tried with SUBSTRING method but that didn't work
Example email: example_email#outlook.com
Output expected: #outlook.com
We can use SPLIT_PART to fetch everything after the # and then append the #:
SELECT CONCAT('#',SPLIT_PART(email, '#', 2)) AS mailDomain
FROM people_practice;
Here the documentation about this and other useful string functions.

#Dblookup and formatting on web

I have been developing a web application using domino, therein I have dblookup-ing the field from notes client; Now, this is working fine but the format of value is missing while using on web.
For example in lotus notes client the field value format is as above
I am one, I am two, I am one , I am two, labbblallalalalalalalalalalalalalalalalalalaallllal
Labbbaalalalallalalalalalaalallaal
Hello there, labblalalallalalalllaalalalalalalalalalalalalalalalalalalalalalalala
Now when I retrieve the value of the field on web it seems it takes 2 immediate after 1. and so forth, I was expecting line feed here which is not happening.
The field above is multi valued field. Also on web I have used computed text which does db lookup from notes client.
Please help me what else could/alternate solution for this case.
Thanks
HD
Your multi-valued field has display options associated with it and the Notes client honors those. Obviously, your options are set up to display entries separated by newlines.
The computed text that you are using for the web does not have options like that and the field options are irrelevant because you aren't displaying the field. Your code has to insert the #Newlines. That's pretty easy because #DbLookup returns a list, and if you concatenate a list and a scalar, the scalar will be appended to each element of the list. (Look at the third example under "concatenation, pairwise" here to see what I mean.
The way you've worded your question is a little unclear to me, but what you need in your computed text formula is either something like this:
list := #DbLookup(etc,. etc.);
list + #Newline;
Or something like this:
multiValueFieldContainingListWithDbLookupResult + #NewLine;
I used #implode(Dblookupreturnedvalue;"");
thanks All :)

Using A Variable prompt and a filter statement for a column value

I am working with an analysis that uses a filter statement to run a calculation on the data. The user wants to be able to change between two different values to view different combinations of scenarios. I keep getting a syntax error on the formula and cant figure out where I am going wrong.
((FILTER(IFNULL("INDRATES"."Client Site Wrap Rate", 0)USING ("Scenario"."Scenario - Default" IN #{"Scenario_1"}{'Forecast'})))-(FILTER(IFNULL("INDRATES"."Client Site Wrap Rate", 0)USING ("Scenario"."Scenario - Default" IN #{"Scenario_2"}{'Plan'}))))
I have been going over and over it and not sure where I am going wrong, any help would be awesome.
Updated code:
(FILTER(IFNULL("INDRATES"."Client Site Wrap Rate",0) USING ("Scenario"."Scenario - Default" = #{Scenario_1}{"Scenario"."Scenario - Default"})))-(FILTER(IFNULL("INDRATES"."Client Site Wrap Rate",0) USING ("Scenario"."Scenario - Default" = #{Scenario_2}{"Scenario"."Scenario - Default"})))
So I have finally resolved the issue so I figured I would post the full answer, and thanks to those who commented, they had components of the answer. So the initial problem we were running into was the IN section which should have been an = sign to finish the FILTER Expression. Secondly, we did not set the filter for Scenario.Scenario - Default to equal a variable expression. third was we were trying to input a default value for Scenario_1 and Scenario_2 which we didnt need in the dashboard (but it does need to be set in order to view it in the analysis). Last, was as the first comment mentioned it did need a single quote ' around the #{Scenario_1} as it was searching for a text value and not a numeric value. The correct syntax and working code is placed below.
((FILTER(IFNULL("INDRATES"."Client Site Wrap Rate",0) USING ("Scenario"."Scenario - Default" = '#{Scenario_1}')))-(FILTER(IFNULL("INDRATES"."Client Site Wrap Rate",0) USING ("Scenario"."Scenario - Default" = '#{Scenario_2}'))))

Trim string up to certain character in sql (oracle)

Looking for some help here if anyone can offer some. I am working with an oracle database and I would like to trim a string up until a certain character '/'. These fields are paths of a URL and they are all different sizes so I need to make sure it's getting to the very last '/' in the URL and removing everything up until that point. Additionally, there is a session ID that is associated with some of these URLs that is located at the end of the string and has a semi-colon before it starts, so I would want to remove everything that contains a semi-colon up to the semi_colon and on. So essentially I want to remove content from the beginning of the URL and from the end of the URL if applicable. Examples of these URL's (string) are as follows:
Current URLS
/ingaccess/jsp/mslogon.jsp
/ingaccess/help/helpie_term_cash_surrender_value.html
/eportal/logout.do;jsessionid=xr8co1kyebrve47xsjwmzw--.p704
/eportal/logout.do;jsessionid=gdh_e_e1m1hna0z9ednklg--.p705
/ingaccess/help/helpie_term_northern_unit_value.html
/ingaccess/help/helpie_scheduled_rebalance.html
/eportal/home.action;jsessionid=9vhfbkhunkvtcm5g1dtgsa--.p704
/ingaccess/help/helpie_catch_up_50.html
/ingaccess/piechartmaker
/ingaccess/help/helpie_term_fund_balance.html
Desired URLS
mslogon.jsp
helpie_term_cash_surrender_value.html
logout.do
logout.do
helpie_term_northern_unit_value.html
helpie_scheduled_rebalance.html
home.action
helpie_catch_up_50.html
piechartmaker
helpie_term_fund_balance.html
Anyone know of an easy fix here? I've tried working with SUBSTR and REPLACE a bit but can't seem to get them to work.
Thanks a bunch in advance,
Ryan
Try this
SELECT CASE WHEN INSTR (surname,';')>0 THEN SUBSTR(surname,1
,INSTR(surname,';',1,1)-1) ELSE surname END FROM
(SELECT SUBSTR(column,INSTR(column,'/',-1)+1) AS surname
FROM tableName)
Tested on Apex

SQL Server find and replace in TEXT field

I have a database in SQL Server 2005 that was brought up from SQL Server 2000 and is still using TEXT type fields instead of varchar(max).
I need to find and replace a string of characters in the text field but all of the examples of how to do this that I have found don't seem like they would work for me. It seems the UPDATETEXT command requires that the two parameters "insert_offset" and "delete_length" be set explicitly but the string i am searching for could show up in the text at any point or even at several points in the same cell. My understanding of these two parameters is that the string im searching for will always be in the same place, so that insert_offset is the number of spaces into the text that the UPDATETEXT command will start replacing text.
Example: Need to find: <u> and Replace it with: <u>
Text field example:
*Everyone in the room was <b><u>tired</u>.</b><br>Then they woke <b><u>up</u>.
Can anyone help me out with this? THANKS!
I finally figured it out. It was buried in the comments to the article jfrobishow published. Thank you SO much.
Here is the whole response that led me to the solution:
quote:Originally posted by fredclown
If you use SQL 2005 you can use replace with a text type. All you have
to do is the below ...
field = replace(cast(field as varchar(max)),'string' ,'replacement')
Easy as pie.
Two thumbs up to Fredclown!!! command
work like a charm for me as well. This
is what I wrote my Update statement to
Find and Replace in a Text field in
SQL server 2005 database
UPDATE TableName SET DBTextField = REPLACE(CAST(DBTextField AS varchar(MAX))
,'SearchText', 'ReplaceText')
FROM TableName
WHERE CHARINDEX('SearchText',CAST(DBTextField as varchar(MAX)))>0
Note:that this may truncate the size of you dbfield , but if is a long text column make it nvarchar(max) and you should not get none truncation!