sql-update

TSQL Dynamic Update of TOP(n) Rows

会有一股神秘感。 提交于 2021-02-20 05:18:49
问题 i have a table with one line per travel second table has values of origin and destination and quantity for each combination i need to run an update that run on the second table that update top N rows on the first table (n comes from the second table) im using this update script inside a cursor in a procedure : ALTER PROCEDURE [dbo].[SP_Travels_History_FromMissing] AS BEGIN SET NOCOUNT ON; DECLARE @C_Day_Type_Code INT = NULL DECLARE @C_PartOfDay_Code INT = NULL DECLARE @C_Station_From INT =

Add auto increment column to existing table ordered by date

狂风中的少年 提交于 2021-02-18 11:57:08
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

Add auto increment column to existing table ordered by date

给你一囗甜甜゛ 提交于 2021-02-18 11:57:07
问题 I have an existing table named "tickets" in database with columns: id (string, Primary Key, contains UUID like e6c49164-545a-43a1-845f-73c5163962f2) date (biginteger, stores epoch) status (string) I need to add new auto increment column ticket_id but the values to be generated should be according to "date" column value. I tried this: ALTER TABLE "tickets" ADD COLUMN "ticket_id" SERIAL; The problem is, it is generating "ticket_id" values in some weird order, looks like it is based on "id"

Update PO status by SQL query

拟墨画扇 提交于 2021-02-17 07:04:10
问题 I am trying to update the PO status from 'r' to 'c' Below is the extraction query. update purchase_order set status = 'c' where STATUS = 'r' and order_date < '2019-01-01'; It was ok to update but now it appears the error message. I wonder what happened? 回答1: Assuming the example select gives all of the rows you want to change and none of the rows you don't: update purchase_order set status = 'c' where STATUS = 'r' and order_date < '2020-01-01'; You have to do this in a separate statement from

Update with 2 joins

会有一股神秘感。 提交于 2021-02-16 20:32:06
问题 I'm trying to update data in 2 distinct tables in the same query with the following code: UPDATE (SELECT s.passNumb, a.hour, a.minute, p.number, s.situation FROM passwords s JOIN atend a ON s.passNumb = a.passNumb JOIN points p ON a.number = p.number WHERE s.passNumb = 1 AND p.number = 1) SET a.hour = TO_CHAR(SYSDATE, 'HH24'), a.minute = TO_CHAR(SYSDATE, 'MI'), s.situation = 'F'; But I'm getting this error: Cannot modify a column which maps to a non key-preserved table . What am I doing wrong

Error: Column does not exist in postgresql for update [duplicate]

假装没事ソ 提交于 2021-02-13 05:48:27
问题 This question already has answers here : Postgres error updating column data (2 answers) PostgreSQL “column ”foo“ does not exist” where foo is the value (1 answer) postgres column “X” does not exist (1 answer) Simple Postgresql Statement - column name does not exists (2 answers) Closed 10 months ago . I am trying to insert a line of text into a column where that column is null. Error listed below. Any help is greatly appreciated UPDATE public.meditech_ar_test4 SET filename = "text" WHERE

Error: Column does not exist in postgresql for update [duplicate]

房东的猫 提交于 2021-02-13 05:45:39
问题 This question already has answers here : Postgres error updating column data (2 answers) PostgreSQL “column ”foo“ does not exist” where foo is the value (1 answer) postgres column “X” does not exist (1 answer) Simple Postgresql Statement - column name does not exists (2 answers) Closed 10 months ago . I am trying to insert a line of text into a column where that column is null. Error listed below. Any help is greatly appreciated UPDATE public.meditech_ar_test4 SET filename = "text" WHERE

How to write an UPDATE Query for multiple tables in Common Table Expressions (CTE's) format?

守給你的承諾、 提交于 2021-02-11 16:52:42
问题 Ho do I rewrite the following UPDATE statement into a Common Table Expressions (CTE's) format? DB::statement('UPDATE taggables, threads SET taggables.created_at = threads.created_at, taggables.updated_at = threads.updated_at WHERE taggables.thread_id = threads.id'); 回答1: I don't really see the point for using a CTE here. Since it seems like your purpose is to update taggables from threads , I would suggest simply using Postgres' update/join syntax, which goes like: update taggables ta set

How to write an UPDATE Query for multiple tables in Common Table Expressions (CTE's) format?

℡╲_俬逩灬. 提交于 2021-02-11 16:52:18
问题 Ho do I rewrite the following UPDATE statement into a Common Table Expressions (CTE's) format? DB::statement('UPDATE taggables, threads SET taggables.created_at = threads.created_at, taggables.updated_at = threads.updated_at WHERE taggables.thread_id = threads.id'); 回答1: I don't really see the point for using a CTE here. Since it seems like your purpose is to update taggables from threads , I would suggest simply using Postgres' update/join syntax, which goes like: update taggables ta set

MySQL Query, problems with with duplicates on insert into

拈花ヽ惹草 提交于 2021-02-11 12:14:06
问题 So I'm using the forum software Xenforo and I need help with a SQL query which will be executed periodically. The forum will have approximately 300-500 active users. So nothing too big. The goal: All users xf_users need to be subscribed to node_id 71 except users which are part of certain user_group_id . Now users can unsubscribe from the forum or change the notify_on and send_alert & send_email fields. I do not want that. So if users 'unsubscribe' they need to be added again. The only