In MySQL I am trying to copy a row with an autoincrement column ID=1 and insert the data into same table as a new row with column ID=2. How can I do this in a single query? Answer Use INSERT … SELECT: where c1, c2, … are all the columns except id. If you want to explicitly insert with an
How to calculate the slope in SQL
I have some data in a sql database and I’d like to calculate the slope. The data has this layout: I’d like the final output to look like this by creating a new table using SQL: To complicate things, not all Keywords have 3 dates worth of data, some have only 2 for instance. The simpler the SQL the…
Simple update query is taking too long
I have a table CurrentStatus in my database (subscription database in a merge replication) Columns are StatusID {Primary Key + Clustered Index}, StatusName, StatusDate, UserID,CreatedDate, …
Trying to trouble Object required error in VBA
I got this problem. I have a form that retrieves a table data using the forms’ record source property. When the form’s opened, I set its record source property to a module’s public method …
Select statement in SQLite recognizing row number
I want to write SQLite statement something like this: but i don’t have such column RowNumber. I have primary key in my table. But is there row number by default that i could use ? Also i am searching info about writing more complicated SQLite statement. So if you have some links in bookmarks please shar…
How to select info from row above?
I want to add a column to my table that is like the following: This is just an example of how the table is structured, the real table is more than 10.000 rows. So for every time there is a value in ‘Subgroup’ I want the (New_Column) to get the value [No_] from the row above There are cases where
SQL Server – Cursor
I am trying to loop through a table using a cursor: That above returns taskResourceOID and EvUserOID. If I need to output a table with the @TaskOID and the respective taskResourceOID and EvUserOID, what is the best way to do it? Answer Use a temporary table or a table variable.. Or even better, don’t us…
Sort by last name and first name
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
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