all groups > sql server programming > july 2007 >
You're in the

sql server programming

group:

Sql Update Query


Sql Update Query YALTA
7/8/2007 8:56:22 PM
sql server programming:
Hello,

I am new to working with SQL and I have a few questions. One the
update query below, one will it work and I looking for a better
understanding of the steps that are taking when this query runs.

begin tran

update address
set phone = xxxxxxxxx,fax = yyyyyyyyyy
from address y inner join
(
select phone, fax from tblmain m
join tbl_address a on m.id = a.id
where phone is null and fax is null
)b join b.id = y.id
where b.y.phone is null and y.fax is null

commit tran

I would think and correct me if I am wrong that these type queries
first pull the data from the selected statement and then will update
the join on the records returned?

Any help would be great
Re: Sql Update Query David Portas
7/8/2007 10:28:35 PM
[quoted text, click to view]

No it won't work. There are at least two syntax errors in it, but since it
is only pseudo-code I can't be sure what the actual code is that you are
going to run...

Be aware that there is a serious flaw with the type of UPDATE statement you
have used. If the join to the table ytou are updating from returns more than
one row for any row in the table being updated then the result is undefined.
You don't get an error message but the end results may not be what you
expected. To avoid that problem you need to be sure that b.id is unique (a
column which you unfortunately left out altogether!).

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--






Re: Sql Update Query YALTA
7/8/2007 11:13:06 PM
Oh, it is on Sybase so I should have posted it on their forum.



On Jul 8, 5:28 pm, "David Portas"
[quoted text, click to view]

AddThis Social Bookmark Button