Best way to replace multiple strings in huge string - sql

Is there any other way to replace multiple strings in sql server 2008r2? which is also fast?
My query is below.
Select REPLACE(REPLACE(EmailText,'#{Name}#',UV.Name),'#{organisation}#',CV.Organisation)
I am written it with example also
Select REPLACE(REPLACE('Hi #{Name}# from #{organisation}#','#{Name}#','Jhon'),'#{organisation}#','Cocacola')

There are all sorts of ways:
A CLR function equivalent to string.Format in C#
String.Format like functionality in T-SQL?
But 'best' as in 'fastest' is probably going to be using REPLACE Repeatedly, as all the attempts in these links have some limitation..

Related

Informatica Coding to SQL

I am attempting to translate the following Informatica code to the equivalent SQL scripts. I am a little stuck as I am not familiar with Informatica and would appreciate any assistance.
The original informatica code reads as follows:
LTRIM(RTRIM(SUBSTR(COV_REINS_CONCAT_BK,11, INSTR(COV_REINS_CONCAT_BK, '|',1,3)-INSTR(COV_REINS_CONCAT_BK, '|',1,2)-1 ))) || 'C'
select LTRIM(RTRIM(SUBSTR(COV_REINS_CONCAT_BK,11,INSTR(COV_REINS_CONCAT_BK,'|',1‌​,3)
-INSTR(COV_REINS_CONCAT_BK,'|',1,2)-1 )))||'C' from TABLE;
Above script will work fine in Oracle. Please replace table with your table name.
It becomes increasingly difficult to port such expressions that make extensive use of INSTR function using the occurrence parameter.
Maybe it's easier to create in your MS-SQL database an INSTR equivalent function that supports the occurrence parameter. See how to create the dbo.INSTR function here.
On this same site you can also see a table with more function equivalences from Oracle to MS-SQL.
Then the expression from the comment becomes much easier to translate:
LTRIM(RTRIM(SUBSTRING(COV_REINS_CONCAT_BK,11,dbo.INSTR(COV_REINS_CONCAT_BK,'|',1‌​,3)
-dbo.INSTR(COV_REINS_CONCAT_BK,'|',1,2)-1 )))+'C'
Here SUBSTR became SUBSTRING, and INSTR became dbo.INSTR and concatenation || was changed to +.
The SUBSTR() and instr() functions are from the Informatica Transformation Language. IMHO it has its roots in function names from Oracle and MSSQL / Sybase function names. This is why it doesn't translate directly to either but is similar. The functions are very well documented in the online help. You'll need to review the switches in the INSTR() function for case sensitivity and the like to ensure their parallel can be written correctly in another tool. The numbers may translate to different things and in some of the Informatica functions the end arguments can be omitted such as, in the SUBSTR() function, meaning that the SUBSTR() will take effect from the numbered position to the end of the string regardless of length. The typing of the port in Informatica can affect the result too, although in this case, the combined function is performing a trim at the end.
SUBSTR() and INSTR() functions are not MS SQL Server functions. I'm guessing the code snippet is Oracle's PL/SQL. Try resources such as http://www.dba-oracle.com/oracle_news/2005_12_16_sql_syntax_differences.htm

PostgreSQL why/when should I use ECPG

I've decided to use postgreSQL as database for a game project(C++).
At the moment I'm using Oracle and it's Pro*C precompiler at work and heard that postgreSQL also has something similar called ECPG.
It's also possible to access data from the the postgres database directly by using the SQL in a string.
So the difference between "normal" and using ECPG, is that you can write your SQL statements like code?, or are there any other differences I should be aware of?.
(PS: i know I'm using it at work, but I haven't noticed any other differences)
Looking forward to hearing from you guys.
Yes, ECPG is covered in the documentation.
So the difference between "normal" and using ECPG, is that you can
write your SQL statements like code?
Well, SQL statements are code. A SQL statement just looks like a SQL statement. This is what a CREATE TABLE statement might look like in ECPG.
EXEC SQL CREATE TABLE foo (number integer, ascii char(16));
ECPG allows variable substitution. (Maybe that's what you meant by "write your SQL statements like code".)
EXEC SQL INSERT INTO sometable VALUES (:v1, 'foo', :v2);
All this stuff is in the documentation.

Create a query to ignore case? VB.net

I'm looking for a way to create a query through a winform application to query an Oracle database but ignoring the case of the data. Is this possible to do without having to modify anything in Oracle itself?
You could simply upper- or lowercase all:
SELECT Columns From Table WHERE UPPER(ColName) = :UpperValue
Then use ToUpper on the value:
yourOracleCommand.Parameters.AddWithValue("UpperValue", value.ToUpper())

Encoding string in order to Insert SQLite

I'm using sqlite3_exec() function in order to execute an SQL Insert command. The problem starts when I need to insert strings that need to be encoded.
For example, I want to insert the following string: "f('hello')". If I want to insert this string I need to change "'" to "''".
My question is, how do I encode these strings? Is there a function I can count on? or a table that details all the needed encodes?
Thanks! :-)
Instead of manually escaping strings (which is error-prone and invites SQL injection attacks), I'd strongly recommend using prepared statements and bind values; read up on sqlite3_bind_XXX and sqlite3_prepare_v2
Using bind values will solve this problem and it will also make sqlite faster because it remembers previously executed sql statements and it can reuse their execution plans. This doesn't work when the sql statement is always slightly different because it hashes the complete sql statement.
sqlite_mprintf supports %q for that.
"Maybe" you should use something like a prepared statement. I am not an expert in SQLite, but I found this link (http://www.sqlite.org/c3ref/stmt.html) and it could help you. It is about SQL Statement Object.

How to modify SQL SELECT results

I need to write a SQL function that will allow me to strip an email address to the bare domain name. EX: I would make JoeSchmoe#mail.google.com read as JoeSchmoe#google.com. This is most likely very simple but, I cannot seem to find any information on it.
If you are using Oracle:
select substr('test#test.com',instr('test#test.com','#')+1,length('test#test.com')) as domain from dual;
You might want to try creating a CLR SQL function and use regex from your .net library to parse the string. From the looks of it you may have to parse the ccTLD if it exists and then parse the generic TLD/domain name.