I have a small little problem. I am have a drop down list that displays all of our customers names. As of right now, the list is sorted by last name (A-Z). But for example, there are 250 people with the last name “Smith”. What I need is a way that the last name of each customer to stay the
Tag: sql
Split time records across midnight
I’m trying to run some reports and having to deal with the whole issue of employee labor hours crossing midnight. It occurs to me though that I could split the records that cross midnight into two records as if the employee clocked out at midnight and simultaneously clocked back in at midnight thus avoi…
How to update selected rows with values from a CSV file in Postgres?
I’m using Postgres and would like to make a big update query that would pick up from a CSV file, lets say I got a table that’s got (id, banana, apple). I’d like to run an update that changes the Bananas and not the Apples, each new Banana and their ID would be in a CSV file. I tried looking
A way to extract from a DateTime value data without seconds
I have an sql DateTime (ms sql server) and want to extract the same date without the seconds: e.g. 2011-11-22 12:14:58.000 to become: 2011-11-22 12:14:00.000 How can I do this? I was thinking to use DATEADD in combination with DATEPART but seems very error prone (besides performance issues) Answer For a solut…
Creating a UDF(User Define Function) if is does not exist and skipping it if it exists
Hi and thanks for reading this. I am trying to use the IF EXISTS/IF NOT EXISTS statement to check if an Object exist. Basically I want to skip it if it is there or create it if it is not there. I …
Selecting by month in PostgreSQL
I want to select rows according to the month of a date or timestamp column like this: But I only get error messages in PostgreSQL. How can this be done? Answer You can use EXTRACT function, like this: Your problem comes from the fact that there is no such thing as Month function in PostgreSQL. Check online do…
Comparing two tables in SQLite
I have two tables and want to compare rows on sqlite like this and I want to produce result like this How is the syntax in sqlite? Thanks Answer
Changing the maximum length of a varchar column?
I’m trying to update the length of a varchar column from 255 characters to 500 without losing the contents. I’ve dropped and re-created tables before but I’ve never been exposed to the alter statement which is what I believe I need to use to do this. I found the documentation here: ALTER TAB…
SQL Top 10 Sales Every Month
Greeting all. I have a SQL 2008 express database, lets name is tbl_Merchant, similar as following: Merchant | Sales | Month Comp.1 100 1 Comp.2 230 1 Comp.3 120 1 Comp.1 …
How to activate the hr schema in Oracle 11g
I am learning PL/SQL and am using SQL Developer cause I created many users with hr schema. But when a user logs in to SQL Developer give an error like the users is invalid. but When I use the system user, it works perfectly but without hr schema. So: How can I activate the hr schema in system user or