SQL Select syntax [duplicate] - sql

This question already has answers here:
What is the use of the square brackets [] in sql statements?
(10 answers)
What does the colon sign ":" do in a SQL query?
(8 answers)
Closed 2 years ago.
I've came cross a SQL SELECT statement which is different than what I normally see:
Select Distinct [Employee: Department_key_historic],[Employee: Department_key_current]
From [shared].[vw_Table]
What does the colon do in the above code? I am used to see format like Select table.columnName but never a :

This appears to be a SQL Server query. If that is the case, [] are used to surround object names. Therefore the : that you see are simply part of the name of the column itself.

Related

MSSQL - substring a value between other values [duplicate]

This question already has answers here:
Turning a Comma Separated string into individual rows
(16 answers)
Closed 2 years ago.
NOIDEHOB_NOIDE1_4321-123
i want to create a querie that extract the following values from the example above:
NOIDEHOB
NOIDE1
4321-123
I need to base the query on the sign _. The values NOIDEHOB, NOIDE1 and 4321-123 are dynamic and the length will vary. There will never be any other _ sign in the string.
Any suggestions?
You can use string_split():
select s.value
from string_split('NOIDEHOB_NOIDE1_4321-123', '_') s

Function to get Pattern R123456 ,Total length=7,start with character and only have digits from 2nd to 7th place [duplicate]

This question already has answers here:
Using RegEx in SQL Server
(6 answers)
Closed 3 years ago.
REGEX is not available in SQL and Cannot have access to Visual Studio .
There is one output here shorturl.at/ovACN but its for MYSQL.
What I need is for SQL.
REGEX is not working with SQL.
When we are trying to do
REGEXP '^[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]'
in SQL its giving non boolean expression error.
How can I get only these patterns (R123456,m123456,y729472) and not like these (R12AS56,mS23456,y7294D2)
Like operator is not working and not getting what exactly I should use to get this output (R123456,m123456,y729472)
MYSQL
where COlumn name REGEXP '^[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]';
ORACLE:
where REGEXP (COlumn nane,'^[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]');
Output = R123456,m123456,y729472
Actual error msg with REGEXP function
If you have this code in MySQL:
where name REGEXP '^[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]'
The equivalent in Oracle is:
where regexp_like(name, '^[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]')
And in SQL Server is:
where name like '[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9]%'

Finding a record with apostrophe using LIKE [duplicate]

This question already has answers here:
PL/SQL, how to escape single quote in a string?
(5 answers)
How to anticipate and escape single quote ' in oracle
(2 answers)
How to handle a single quote in Oracle SQL
(2 answers)
Closed 4 years ago.
I need to find a below record
O'GRAD
I wanted to use LIKE
LIKE 'O'GRAD'
But i come across a problem with apostrophe.
What would be the best way around it?
Double up the apostrophe
LIKE 'O''GRAD'
or use the Q syntax
LIKE q'{O'GRAD}'
if your Oracle DB version is 10g or upper you may use :
select *
from mytable t
where t.col1 like '%'||q'$O'GRAD$'||'%';
/
or classically add an extra quote to existing quote
select *
from mytable t
where like '%'||'O''GRAD'||'%';
/
to overcome the single quotation mark problem.

How to escape single quotes in Oracle? [duplicate]

This question already has answers here:
How to handle a single quote in Oracle SQL
(2 answers)
Closed 7 years ago.
I have a column containing certain expressions stored as a text string which include single quotatons, such as 'missed transaction' (INCLUDING the quotations)
How can I use a where clause with such an occurance?
select * from table where reason = ''missed transaction''
doesn't work, and I can't use the replace function because it also requires single quotations in its syntax. Obscure problem, i know. But thanks for any help.
You need to escape the ' by doubling them :
select * from table where reason = '''missed transaction''';
The q quote syntax makes this sort of thing easier:
select * from table where reason = q'['missed transaction']'
Everything between the '[ and the ]' is interpreted literally, so no need to double all the quotes, however many there may be.

How do i remove character in a column data using sql [duplicate]

This question already has answers here:
removing characters from field in MS Access database table
(4 answers)
Closed 8 years ago.
I have table with data like
samcol
60.78686
46.0000
45.43240
56.3453450
And i'm trying to remove '.' before decimal places. And table should looks like
samcol
6078686
460000
4543240
563453450
Use Replace String function to replace all the . with empty string
Select Replace(samcol,'.','') from yourtable