sql-update

How to update one table from another table based on some priority that depends on where clause?

為{幸葍}努か 提交于 2020-04-17 22:04:53
问题 I have table A with product_id,cost,year,quarter,... etc columns. I have another table B with product_id,base_cost,current_year,p_year,p_quarter,p_order columns. I want to write an update query to update A from B. My conditions are - WHERE A.product_id=B.product_id and A.year=B.current_year and (A.year=B.p_year and A.quarter>B.p_quarter) or A.year>B.p_year and A.cost=0; But the problem is, with these conditions if i have more than one rows in B then i only want to update from the row of B

Update SQL data but the data contains ' so I get errors

谁说我不能喝 提交于 2020-04-17 20:39:56
问题 I'm trying to update SQL data but it contains ' so I get errors. The SQL statement looks like this: UPDATE SystemConfiguration SET HeaderScript = '<script> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],' WHERE ID = 1 I tried to replace the quote with " but I get error. I also tried without quote I get error as well. Any suggestions. 回答1: You need to double the single quotes to escape them: UPDATE

Update SQL data but the data contains ' so I get errors

淺唱寂寞╮ 提交于 2020-04-17 20:38:51
问题 I'm trying to update SQL data but it contains ' so I get errors. The SQL statement looks like this: UPDATE SystemConfiguration SET HeaderScript = '<script> (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],' WHERE ID = 1 I tried to replace the quote with " but I get error. I also tried without quote I get error as well. Any suggestions. 回答1: You need to double the single quotes to escape them: UPDATE

How i can Replace Only first Result in SQL Function

℡╲_俬逩灬. 提交于 2020-04-16 03:46:25
问题 I will ask about SQL replacement function. I need to your bits of help. In Wordpress DB, I must change a little part. I want to replace first result only in a column. I will explain by giving an example, My string is = "Hello XXX tomorrow we XXX will meeting in XXX Dubai, Do you want join us XXX ? " My result must be like this= "Hello MMM tomorrow we XXX will meeting in XXX Dubai, Do you want join us XXX ? " in this example, we putted MMM to first result of XXX . How i can do it ? I tried

Update in Batches Never Finishes

£可爱£侵袭症+ 提交于 2020-03-25 21:11:33
问题 as a follow up on my question original question posted here UPDATE in Batches Does Not End and Remaining Data Does Not Get Updated If you use the logic below you'll see that update never finishes. Let me know if you have any ideas why... Table 1 IF OBJECT_ID('tempdb..#Table2') IS NOT NULL BEGIN DROP TABLE #Table2; END CREATE TABLE #Table2 (ID INT); DECLARE @Count int = 0; WHILE (select count(*) from #Table2) < 10000 BEGIN INSERT INTO #Table2 (ID) VALUES (@Count) -- Make sure we have a unique

How can I write the NULL in database with C#

杀马特。学长 韩版系。学妹 提交于 2020-03-22 09:07:03
问题 I have A table and B table. B table update everyday according to changes from A table. in A table 2 entities like : SCD_DEPT (String Value) and LEAVE_DATE(DateTime) and in A table empty values are looking "NULL" for SCD_DEPT and LEAVE_DATE but in B table empty SCD_DEPT values are looking empty. I want to empty SCD_DEPT values looks "NULL" in B table it's my UPDATE part in my code var employeequery = $"{UpdateQuery} EMAIL=@EMAIL, GID = @GID, SAP_COMPANY_CODE=@SAP_COMPANY_CODE, FIRST_NAME=

How can I write the NULL in database with C#

旧时模样 提交于 2020-03-22 09:06:30
问题 I have A table and B table. B table update everyday according to changes from A table. in A table 2 entities like : SCD_DEPT (String Value) and LEAVE_DATE(DateTime) and in A table empty values are looking "NULL" for SCD_DEPT and LEAVE_DATE but in B table empty SCD_DEPT values are looking empty. I want to empty SCD_DEPT values looks "NULL" in B table it's my UPDATE part in my code var employeequery = $"{UpdateQuery} EMAIL=@EMAIL, GID = @GID, SAP_COMPANY_CODE=@SAP_COMPANY_CODE, FIRST_NAME=

Sql Query for increase item value price for multiple item

老子叫甜甜 提交于 2020-03-02 03:24:39
问题 I want to write Sql Query for increase item price by percentage. Scenario is :- In table, I have 3 coloumn : ID, Item-Name, Price Example : If item-Name is T-shirt, Increase price by 10% item-Name is Jins , Increase price by 50% item-Name is top , Increase price by 5% 回答1: If you are looking to update the table you can do conditional update. update table_name set price = case when `Item-Name` = 'T-shirt' then price+( (price*10) /100 ) when `Item-Name` = 'Jins' then price+( (price*50) /100 )

Sql Query for increase item value price for multiple item

耗尽温柔 提交于 2020-03-02 03:21:21
问题 I want to write Sql Query for increase item price by percentage. Scenario is :- In table, I have 3 coloumn : ID, Item-Name, Price Example : If item-Name is T-shirt, Increase price by 10% item-Name is Jins , Increase price by 50% item-Name is top , Increase price by 5% 回答1: If you are looking to update the table you can do conditional update. update table_name set price = case when `Item-Name` = 'T-shirt' then price+( (price*10) /100 ) when `Item-Name` = 'Jins' then price+( (price*50) /100 )

Instead of trigger to update view with multiple tables

非 Y 不嫁゛ 提交于 2020-03-01 05:07:48
问题 I am trying to find an example of how to update a view on multiple tables using an instead of trigger. That is I want update more than one table that this view selects from. I cant find any examples. If someone can show me how to this that would be great. 回答1: Assuming that you're using SQLServer here is one oversimplified example CREATE TABLE persons (personid int, firstname varchar(32), lastname varchar(32)); CREATE TABLE employees (employeeid int, personid int, title varchar(32)); CREATE