I have a table called flags that contains a column called coordinates that is full of MySQL ‘points’. I need to perform a query where I get all the flags within a circle based on a latitude and longitude position with 100m radius. From a usage point of view this is based around the user’s po…
Proper way of checking if row exists in table in PL/SQL block
I was writing some tasks yesterday and it struck me that I don’t really know THE PROPER and ACCEPTED way of checking if row exists in table when I’m using PL/SQL. For examples sake let’s use table: …
How to do a batch commit in plpgsql?
When I do the below function, some errors occurs: Here is my sample code. So could anyone give me a sample of how to finish my job as the above code? I’m using PostgreSQL 9.2. Answer In general, I think there are three approaches you can take: Do without. Just let the whole thing be committed at once, l…
MS Access Select top n query grouped by multiple fields
This is part 2 of a problem that was already answered by peterm on this board. Thanks again peterm! So I have code that will return the top 3 test scores for a given student. My table looks like …
How to find last weekday of current month using SQL
How would I calculate the last weekday of the current month given a date using SQL? I was able to get the last day of current month, but not sure how to do the last weekday programmatically. I don’t want to generate a calendar look-up table. Here’s the last day of month code i’m currently us…
Postgres Error: More than one row returned by a subquery used as an expression
I have two separate databases. I am trying to update a column in one database to the values of a column from the other database: UPDATE customer SET customer_id= (SELECT t1 FROM dblink(‘port=5432, …
MSSQL BIT_COUNT (Hammingdistance)
Is there any function similar to the MYSQL BIT_COUNT function in MSSQL? I want to create a very simple Hammingdistance function in MSSQL that i can use in my selects. Here is what i have for MYSQL: Answer Why not just write your own bit_count code in T-SQL? There’s no need to use SQL CLR if all you need…
How can I update date of datetime field with mysql only?
I have a table like this I want to update only the date but dont know where to start from. I mean in the datetime field date i want to update the date ‘2014-01-08’ to ‘2014-01-01’. How can i do that? I have tried this. Here is the Fiddle Structure Answer One option is to use this: Fidd…
SQL query how to get the local variable
I have this query and I want to get “page” variable which is created: How can I get it in the query to make a procedure to search. and page = @page; Answer
How to know if a user has a privilege on Object?
I would like to know if a user has a privilege on an object or not. I’m working on SQL Developer. When I query manually the table DBA_TAB_PRIVS, I get all the information needed. However, I need this information to be used in some triggers and functions. So, I’m writing PL/SQL function that will r…