sql-update

TSQL Update statement with Join

て烟熏妆下的殇ゞ 提交于 2020-01-03 17:24:30
问题 I have two tables with a parent/child relationship. I want to update the parent with data from the child. However assuming there are 2 children I would like to be able to pick which child is used for the update depending on some other column from the child. Here is what I have so far: Parent: @test Child: @exdat Expected outcome, result of parent after update should contain only Capital letters. I want to update the parent with some data from the child, but if more than one exists I'd rather

Update statement using a WHERE clause that contains columns with null Values

北城余情 提交于 2020-01-03 07:28:15
问题 I am updating a column on one table using data from another table. The WHERE clause is based on multiple columns and some of the columns are null. From my thinking, this nulls are what are throwing off your standard UPDATE TABLE SET X=Y WHERE A=B statement. See this SQL Fiddle of the two tables where am trying to update table_one based on data from table_two . My query currently looks like this: UPDATE table_one SET table_one.x = table_two.y FROM table_two WHERE table_one.invoice_number =

Call to a member function bind_param() on a non-object. mysqli [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-03 06:41:28
问题 This question already has answers here : Call to a member function bind_param() on a non-object MySQLi (3 answers) Closed 6 years ago . This is my php code: include ("dbinfo.php"); if(isset($_POST['editsave'])){ $edittitle=$_POST["edittitle"]; $editurl=$_POST["editurl"]; $editdesc=$_POST["editdesc"]; $editid=$_POST["editid"]; $mysqli = $GLOBALS['dbc']; $stmt = $mysqli->prepare("UPDATE links SET title = ?, \desc = ? WHERE id = ?"); $stmt->bind_param('ssd', $_POST['edittitle'], $_POST['editdesc

SQL: how query in sql order by created in this case

南楼画角 提交于 2020-01-03 02:50:24
问题 select consultas.id as a, consultas.clasificacion as cl, consultas.paciente_id as b, consultas.created,imc_kg_m2 as im from consultas join signos_sintomas on signos_sintomas.consulta_id = consultas.id where paciente_id in (select pacientes.id from pacientes where pacientes.id < 30 order by pacientes.id desc) and consultas.created in (select consultas.created from consultas order by consultas.created asc ) and imc_kg_m2 is not null ; +-----+----+----+---------------------+------+ | a | cl | b

Best way to write PHP SQL Update Statement

喜你入骨 提交于 2020-01-02 16:19:34
问题 I have this PHP SQL statement: $updateCategory = "UPDATE category SET name=".$name.", description=".$description.", parent=".$parent.", active=".$active." WHERE id=".$catID.""; What is the best way to write this? Thanks, Chris. 回答1: I suggest you use prepared statements instead of concatenating the query string together: $sql = 'UPDATE category SET name=:name, description=:description, parent=:parent, active=:active WHERE id=:catID'; if you are using PDO, which I strongly suggest, you would

Using dynamic query + user defined datatype in Postgres

扶醉桌前 提交于 2020-01-02 10:26:11
问题 I need a function to normalize my input table features values. My features table has 9 columns out of which x1,x2...x6 are the input columns I need to scale. I'm able to do it by using a static query: create or replace function scale_function() returns void as $$ declare tav1 features%rowtype; rang1 features%rowtype; begin select avg(n),avg(x0),avg(x1),avg(x2),avg(x3),avg(x4),avg(x5),avg(x6),avg(y) into tav1 from features; select max(n)-min(n),max(x0)-min(x0),max(x1)-min(x1),max(x2)-min(x2)

Update column with random value

会有一股神秘感。 提交于 2020-01-02 04:43:05
问题 I have a table: ID | VALUE | DATE 1 | 5 | 2012-10-01 2 | 7 | 2012-10-02 3 | 3 | 2012-10-05 4 | 0 | 2012-05-07 I want to add on the top of the current value with the VALUE random individually BETWEEN 1 AND 5. Let say: ID | VALUE | RANDOM VALUE 1 | 5 | 0 2 | 7 | 2 3 | 3 | 3 4 | 0 | 6 NEW VALUE ID | VALUE 1 | 5 2 | 9 3 | 6 4 | 6 How do I do this? All I can think of is by doing cursor type of query. Any help? 回答1: Try UPDATE TABLE SET VALUE=VALUE+ROUND(1+RAND()*4); 回答2: This will update the value

Conversion of the nvarchar value '3001822585' overflowed an int column

泄露秘密 提交于 2020-01-02 04:27:09
问题 I use following to import Excel file to SQL Server. The Excel file has all the values as string. I am able to import the file except Barcode , SalePrice and Price2 . I get error Conversion of the nvarchar value '3001822585'(barcode) overflowed an int column Code: SqlCommand sqlcmd = new SqlCommand (@"MERGE Inventory AS target USING (SELECT LocalSKU, ItemName, QOH, Price, Discontinued,Barcode, Integer2 ,Integer3, SalePrice, SaleOn, Price2 FROM @source) AS Source ON (Source.LocalSKU = target

SQL - WHERE clause on each SET command in UPDATE?

随声附和 提交于 2020-01-02 03:17:09
问题 I'm trying to create an SQL query in PHP to update a table. Is it possible to have a different WHERE clause for each affected row? eg something like: UPDATE table SET val=X WHERE someproperty = 1, SET val=Y WHERE someproperty = 2 etc? Any help appreciated. Thanks 回答1: You cannot have multiple WHERE clauses for any SQL statement, however you can use a CASE statement to accomplish what you are trying to do. Another option that you have is to execute multiple UPDATE statements. Here is a sample

How to conditionally INSERT OR REPLACE a row in SQLite?

∥☆過路亽.° 提交于 2020-01-02 00:53:10
问题 I would like to insert or replace_on_condition. If the condition is not satisfied, do not insert or replace. Is this possible? For my project, I currently have two data collection processes. One is fast but doesn't catch everything. The other is slow but catches everything. With the fast process, I get data almost in real time. With the slow one I get data using a batch process at the end of day. My issue is this: sometimes the fast process will "Complete" a record (meaning it no longer needs