473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

query: if exists UPDATE else INSERT?

------=_NextPart_000_003E_01C34934.FBC032B0
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hello,

I'm looking for a solution to write a sql query that inserts a set of =
data if the data id is not present and otherwise update the set.

I have a table with id (char(8)) and value (int(8))

To make my problem clear:

There is no set with id =3D "20030713"
insert into table values ("20030713","10");

The next set is ("20030713","20") but as a set with 20030713 is already =
available I like to have
update table set value =3D value + 20 where id =3D "20030713"

I tried the "replace" command but I fail to get the "value =3D value + =
20" working.

The problem is that the query is called from within a programm that only =
can call a query but not get some data back.

Also a solution in form of

mysql>
$w =3D select value from table where id =3D "20030713";
delete from table where id =3D "20030713";
insert into table values ("20030713",$w + 20);
<mysql

would be fine but I think that $w =3D part isn't working with mysql ;-)

Its no solution to simply make the table accept duplicate entries for id =
and make a "sum(value) group by id" because I think it will be a =
performace problem if I have thousends of datasets a day - If I'm wrong =
let me know.

Any hints how to manage this??

Alexander Newald
------=_NextPart_000_003E_01C34934.FBC032B0--

Jul 19 '05 #1
0 13258

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
5
by: Muhd | last post by:
To start off i have a database table that consists of "profiles", another that consists of "users" and finally one that consists of "exclusions", these are defined in the DDL below. I am trying to...
22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
2
by: Bane | last post by:
Hi all In the SP below im (trying to) do some dynamic sql. As you can see the table to use is set as a variable and the 'exec' method used to run the sqlstatements. My problem is that the 'if...
5
by: Glenn | last post by:
Hi! Server info - Win2K3 Server +SP1 with 1 GB Memory and 1.5 GB Virtual Memory SQL Server 2000 Enterprise Edition + SP3 running on this. Required result - Create a SQL Script that will...
7
by: chriskoch | last post by:
I am running a DTS Package. I have a temp table with 1494 records. I am inserting a 'Y' or 'N'into a temp table #HasClaims. The TempTable name with the Provider Id's(PRPR_ID) is...
1
by: JellyMan | last post by:
I am trying to do something with an Access SQL query that I have never done. I can see how it SHOULD work in my head, but can't seem to make it work in reality. I think I have it close, but my SQL...
0
by: Hurricane | last post by:
I have my SQL database with a table that I am trying to have a gridview dislay with inline editing. It seems as if the dataset does not generate the apropriate update query, and therefore...
5
by: yuva17raj | last post by:
hi i am trying to update my sql table data with the csv/excel file data my sql table is as follows test test1 23 usd 25 ero 34 test and my csv file has
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.