How to run Regex in MSaccess (If supported)? [duplicate] - sql

This question already has answers here:
Regular Expressions in MS Access VBA?
(2 answers)
Closed 4 years ago.
This is my first post, please be nice.
I want to know if it is possible to run similar to an Oracle regexp_match/regexp_replace in MSaccess 2010.
The code I usually use is something like
select * from table
where regexp_match(name, '^foo$')
How do I do this in Access,
Yes I have tried google search, unfortunately I was unsuccessful.
Do I have to use VBA for it, if so how?
Thank you, much appreciated

MS Access does not have built-in regular expression support.
However, this query:
select t.*
from table t
where regexp_match(t.name, '^foo$')
Is better written as:
select t.*
from table t
where t.name = 'foo';
Equality is more efficient in any database.

Related

decipher this postgresql syntax? [duplicate]

This question already has answers here:
How can I comment special \ commands in PostgreSQL's psql commandline tool?
(5 answers)
Closed 8 years ago.
I have a query in an excel file that I inherited from the previous user/creator of the tool. The external connection is to a PostgreSQL database. Here's the line of script that I need to decipher so that I can hopefully adjust the date range for the query:
with
icon_date as (select max(icon.date::date)/* '1/1/2014'::date*/ as icon_date from pmm.icon)
...
pmm is the schema and .icon is the table name
My specific question is what this part means:
/* '1/1/2014'::date*/
I have no clue what surrounding a date::data type with /* */ would do in the first part of the query. Any ideas? I can post more of query if that would help.
That is just a comment and it will be ignored.
There are (at least) two ways to put comments into SQL:
everything after -- until end of line
everything between /* and */ (even spanning lines)
My guess is that this is code left over from testing, where instead of the max you would select some fixed date (because it is faster, or data was missing).

How does separated clause and args protect against SQL injection? [duplicate]

This question already has answers here:
How can prepared statements protect from SQL injection attacks?
(10 answers)
Closed 8 years ago.
I heard that separated SQL clause and args can protect against SQL injection. For example,
clause = SELECT * WHERE ID = ? AND NAME = ?
with ID = 23, and NAME = "Tom".
Can someone explain to me how it works?
Basically, you're making the distinction between data and the actual code (query part) very clear. You're telling the SQL server: this is clearly data and this is clearly code.
This way, you're basically skipping the part where the server has to pull apart the code and data from your query so there's no chance the server can misinterpret bits of data as part of your query.
Edit: as per the link in the comments, this answer pretty much answers your question much better than I've explained here.

SQL Server Replace Command with WIldcard [duplicate]

This question already has answers here:
Perform regex (replace) in an SQL query
(5 answers)
Closed 5 years ago.
I am in need of some help. Thanks to fellow user davids, I was able to get certain things working within SQL Server and am in need of some more help. Here is what I am trying to do:
UPDATE Table1 SET keyfield=(REPLACE(REPLACE(Column1,'http://*/folder/',''),'.avi',''))
UPDATE Table2 SET keyfield=(REPLACE(REPLACE(Column2,'http://server2/folder/',''),'.mpg',''))
Can anyone help me out or point me in the right direction to get the wildcard to work? This particular column, the * is an IP Address and it will change all the time. Granted I will know the IP's ahead of time and can probably do it one by one, but I would prefer to have it automatically replace. Thanks in advance!
You should look into regular expressions.
My google karma found this article in MSDN Magazine.
Edit:
See also:
Perform regex (replace) in an SQL query

sql server select from case db [duplicate]

This question already has answers here:
How to use a variable for the database name in T-SQL?
(4 answers)
Closed 8 years ago.
I have 2 db on one server.
I need to write procedure that does select basing on #db variable.
I know 2 possibilities for this:
I declare #SQL nvarchar(max) and generating my query in plain text. Then i do exec #SQL.
Bad variant imho.
I do 2 similar queries and use if #db='' 1st query else 2nd query. Another bad variant because it is code duplicate.
Question is - is there any way to do like this or similar: select * from #db.dbo.table?
Using "exec #SQL" isn't evil. If it gets the job done and you're not exposing yourself to any security risks then it may be the best way to go. Another option would be to consider using a real programming language like c# (or whatever your preference is) since they are better equipped to handle these sort of dynamic requirements.

Should we end the statement in T-SQL with semi-colon? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
When should I use semicolons in SQL Server?
When we are writing a SQL script in T-SQL, should we end each statement with a semi-colon? Does semi-colon work like 'GO' keyword? As of now, I see that it doesn't really matter, but I would like to know which is the best practice?
It's good to get into the habit now because CTE/WITH and MERGE need it, as well as some Service broker stuff as mentioned in the other question. Of course, you could use ;WITH cTE AS ...
C# etc monkeys have been doing it for years.
It won't work with GO because it isn't a keyword. It's a directive for SSMS and other tools to break a larger script into batches.