How i can use REGEXP_REPLACE in SQL Server - sql

I asked a question but answer is not usable on my computer.
How i can Replace Only first Result in SQL Function
here, the result is using REGEXP_REPLACE function but I cant use it on SSMS 18
it is getting this error;
REGEXP_REPLACE is not a recognized built-in function name
How I can use this function?

Related

Convert ORA_HASH to SQL Server

I am trying to convert an Oracle query to a SQL Server and facing an issue. Can you please help me ?
Oracle Query:
select ORA_HASH(SYS_GUID()) as SEGMENTID from my_Table
I am looking for a function which is equivalent to ORA_HASH() function in SQL Server. I was searching in google and found that HASHBYTES() function is the one which works as ORA_HASH in SQL Server. But when I tried to use, the return value of this is Hexa decimal and on the other hand, ORA_HASH is returning an integer.
Can you please help me in proving the equivalent function to ORA_HASH in SQL Server which works same as ORA_HASH ?
You shall try CHECKSUM which as per doc is intended for use in building hash indexes. https://learn.microsoft.com/en-us/sql/t-sql/functions/checksum-transact-sql

REGEXP_CONTAINS not recognized

Happy new years, stackoverflow!
I am trying to use some regex functions in bigquery but some of them return error as if I have the name wrong.
SELECT REGEXP_CONTAINS(path, r'^abc$') FROM [tablename]
Query Failed
Error: 2.24 - 2.26: Unrecognized function regexp_contains
Where as if I do a similar regex function, the function text in the editor changes color and the query works.
SELECT REGEXP_EXTRACT(path, r'^abc$') FROM [tablename]
It should work since it's documented in this link.
Does anyone know how to fix this?
BigQuery Legacy SQL and Standard SQL support different set of regular expression functions
Legacy SQL Regular Expression Functions:
REGEXP_MATCH, REGEXP_EXTRACT and REGEXP_REPLACE
Standard SQL Regular Expression Functions:
REGEXP_CONTAINS, REGEXP_EXTRACT, REGEXP_EXTRACT_ALL and REGEXP_REPLACE
So, in your case just make sure you use proper BigQuery SQL dialect
#standardSQL
SELECT REGEXP_CONTAINS(path, r'^abc$') FROM [tablename]

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

Data type in sybase function replace() instead of value

Hi I have a Sybase sql query where function replace() is used like this replace(Table1.Col1,char(10),'')
When transfering the query to Netezza There is a problem at the beginning of char(10).
I dont understand what was the char(10) for ? From Sybase manuals : REPLACE ( original-string, search-string, replace-string ) there should be a search string but instead there is a data type.
What could I replace with this char(10) that Netezza would accept.
Replace isn't native in Netezza however it is included in the Netezza SQL Extensions Toolkit
Replace Works like the example below:
replace('ORIGINAL VALUE','VALUE TO REPLACE','REPLACE WITH THIS')
replace(Table1.Col1,' ','')
In the second example the function will replace any space with nothing.

How to replace all string in SQL Server 2005?

In postgresql database have one function btrim(string text [, characters text]).
For examples
btrim('xwxpostsqlwwx', 'wx')
In this function return value postsql.
Like this I need to do in SQL Server 2005. Is there any similar builtin function available in SQL Server?
REPLACE, SUBSTRING,CHARINDEX
http://msdn.microsoft.com/en-us/library/ms181984.aspx
I don't know of any exact equivalent, but you should be able to achieve the same results using SQLServer's Regular Expression functionality.
I believe there is no such a built-in function, but you can create your own if you like. You can find an example of a function doing exactly what you want here (at the bottom of the page).