Ask a Question related to ASP Database, Design and Development.
-
Laphan #1
A sort of IF THEN ELSE in SQL
Hi All
I know this isn't an SQL syntax NG per say (esp MySQL), but there are far
more legible gurus in here than the MySQL groups so I hope you will bear
with me.
All I want to know is if there is a sort of IF ... THEN ... ELSE command in
MySQL? The reason being that if a product code exists then I want to do an
update, but if it doesn't then I want to do an insert.
At the moment, I'm having to do a Select query first to see if it does exist
and then do a 2nd update/insert query depending on the result I get from the
1st.
I'd like to sort this into one query if poss so your feedback would be
appreciated.
Rgds
Laphan
Laphan Guest
-
Sort
Hi, I want to write a perl script to do something like this Abc 12.8 8 "left" 1 15.7 Def 13.8 9 "top" 0 19.7 -
[ANN] Sort::Key 0.02
Hi, I have released Sort::Key 0.02, a module for sorting objects by some key. It's really fast, usually much faster than perl core sort... -
Sort bug
It appears that the runtime cannot sort a datagrid column when the items in the column contain a NaN or Infinity. Is there a way to override the... -
memory sort and disk sort
I check the sysprofile table and find there are 700 times disk sort, I think it is lack of sort memory. I want to turn all the disk sort into the... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp... -
Aaron [SQL Server MVP] #2
Re: A sort of IF THEN ELSE in SQL
> At the moment, I'm having to do a Select query first to see if it does
existthe> and then do a 2nd update/insert query depending on the result I get fromYou're going to have to do that anyway, I think. In SQL Server, I do this:> 1st.
IF EXISTS (SELECT 1 FROM tbl WHERE <logic to determine uniqueness>)
UPDATE tbl ... WHERE <logic to determine uniqueness>
ELSE
INSERT ...
A roughly performance-equivalent alternative is:
UPDATE tbl ... WHERE <logic to determine uniqueness>
IF @@ROWCOUNT = 0
INSERT ...
For MySQL specifics (e.g. whether the EXISTS clause exists, or something
similar), you'll probably have better luck in a MySQL newsgroup or from the
MySQL docs.
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
Aaron [SQL Server MVP] Guest
-
Laphan #3
Re: A sort of IF THEN ELSE in SQL
Thanks for the feedback Aaron
Much appreciated.
Rgds
Laphan
Aaron [SQL Server MVP] <ten.xoc@dnartreb.noraa> wrote in message
news:e0ECx$IWEHA.2696@TK2MSFTNGP09.phx.gbl...exist> At the moment, I'm having to do a Select query first to see if it doesthe> and then do a 2nd update/insert query depending on the result I get fromYou're going to have to do that anyway, I think. In SQL Server, I do this:> 1st.
IF EXISTS (SELECT 1 FROM tbl WHERE <logic to determine uniqueness>)
UPDATE tbl ... WHERE <logic to determine uniqueness>
ELSE
INSERT ...
A roughly performance-equivalent alternative is:
UPDATE tbl ... WHERE <logic to determine uniqueness>
IF @@ROWCOUNT = 0
INSERT ...
For MySQL specifics (e.g. whether the EXISTS clause exists, or something
similar), you'll probably have better luck in a MySQL newsgroup or from the
MySQL docs.
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
Laphan Guest



Reply With Quote

