I am writing a SP, using PL/pgSQL. I want to return a record, comprised of fields from several different tables. Could look something like this: CREATE OR REPLACE FUNCTION get_object_fields(name text)…
Select count of rows in another table in a Postgres SELECT statement
I don’t know quite how to phrase this so please help me with the title as well. 🙂 I have two tables. Let’s call them A and B. The B table has a a_id foreign key that points at A.id. Now I would like to write a SELECT statement that fetches all A records, with an additional column containing the
How to extract year and month from date in PostgreSQL without using to_char() function?
I want to select sql: SELECT “year-month” from table group by “year-month” AND order by date, where year-month – format for date “1978-01″,”1923-12”. select to_char of couse work, but not “right” order: Answer e.g. http://www.postgresql.org/doc…
Converting Select results into Insert script – SQL Server [closed]
I have SQL Server 2008, SQL Server Management Studio. I need to select data from Table1 in database1. Then I have to edit some values in the results and insert values into Table1 in database2. Or …
MySQL “IN” operator performance on (large?) number of values
I have been experimenting with Redis and MongoDB lately and it would seem that there are often cases where you would store an array of id’s in either MongoDB or Redis. I’ll stick with Redis for this question since I am asking about the MySQL IN operator. I was wondering how performant it is to lis…
Select Nth Row From A Table In Oracle
How can I select the Nth row from a table in Oracle? I tried but that didn’t work. Please help! Answer Based on the classic answer: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:127412348064
Detect overlapping date ranges from the same table
I have a table with the following data And want to get the following results Any ideas on where to start? A lot of the reading I’ve done suggests I need to create entries and for each day and join on matching days, is this the only way? Answer If you already have entries for each day that should work,
MS SQL query to list count by status
I want to achieved the result below. I want to list all records having a status of “For Approval” together with this condition: For example for Username ‘Leo’ Then sum all the status having “For Approval” which is the checker is ‘Leo’ with the condition above An…
T-SQL Conditional WHERE Clause
Found a couple of similar questions here on this, but couldn’t figure out how to apply to my scenario. My function has a parameter called @IncludeBelow. Values are 0 or 1 (BIT). I have this query: If @IncludeBelow is 0, i need the query to be this: If @IncludeBelow is 1, that last line needs to be exclu…
Entity Framework and SQL Server adds blanks in strings?
I am building a ASP.NET MVC application with Entity Framework and SQL Server. I have noticed that when I read back SQL Server columns of type nchar or text there will be added blanks at the end of …