Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-11-2004, 05:09 AM   #1
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
SQL - complicated query

Hi,

suppose i have a table with a single column. And i wanna do query that does the following:

if table is empty
insert value x into the table
else // here in this case the table will have one row ONLY
update the only existing row to value x
end

is it possible to do something like "insert or update" query?
M.D. is offline   Reply With Quote
Old 10-11-2004, 08:44 AM   #2
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Here is some psuedocode you could use in your program:

Code:
recordset = "SELECT Count(*) AS NumRecords FROM TableName"

if recordset(NumRecords) > 0 then
   //record already exists, delete it
   RunSQL("DELETE FROM TableName")
end if

//the table is empty, insert the new
RunSQL("INSERT INTO TableName VALUES(" + Value + ")"
This will delete the value if it already exists and then insert the value you want. It is best not to have 2 different queries (an Insert and Update) to modify a single value if you can avoid it.
faulkner132 is offline   Reply With Quote
Old 10-11-2004, 08:57 AM   #3
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
tnx

i will do:

count rows
if rows > 0
update
else
insert
end

tnx alot
M.D. is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:54 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2