473,326 Members | 2,126 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,326 software developers and data experts.

MULTI-Table Update Queries

I'm new to adp w/ sql server but I have to use it on a project i'm
doing...
One of the MUSTS for this project is the ability to update a 00 - 09
text value with the appropriate text description from another table...
Easy as pie in .mdb. Of course In the stored procedure it barks at me
and tells me that an update query can only have one table.. ouch that
hurts...
I'm currently reading on the subject but this group has been very
helpful in the past.....

I found this link...
http://www.sqlservercentral.com/colu...theeasyway.asp

Unfortunetly I'm using MSDE not Enterprise so I don't think I can use
the query analyser.. But I tryed it in my Access ADP anyway
it barked at me..

I tried to go from this....

SELECT dbo.LU_SEX.SEX_CODE, dbo.TEST.DEFECTS_DP1
FROM dbo.TEST INNER JOIN
dbo.LU_SEX ON dbo.TEST.SEX_DP1 =
dbo.LU_SEX.SEX_DEC

To this...

UPDATE dbo.TEST.SEX_DP1
SET dbo.TEST.SEX_DP1 = dbo.LU_SEX.SEX_CODE
FROM dbo.LU_SEX INNER JOIN
dbo.TEST ON dbo.LU_SEX.SEX_DEC =
dbo.TEST.SEX_DP1

Maybe I need a good book on this?

Thanks,
Charles

Jul 23 '05 #1
2 8289
It looks like you wanted:

UPDATE dbo.TEST
SET dbo.TEST.SEX_DP1 = dbo.LU_SEX.SEX_CODE
FROM dbo.LU_SEX
JOIN dbo.TEST
ON dbo.LU_SEX.SEX_DEC = dbo.TEST.SEX_DP1

The table name follows the UPDATE keyword, not the column name.

This is the MS proprietary syntax for an UPDATE statement. There is a
potential problem with that method if you try to update using a join
that doesn't return a unique value for each row. No error is returned
but the result is undefined and may be unreliable. This is one reason I
prefer the ANSI Standard UPDATE syntax, which SQL Server also supports:

UPDATE Test
SET sex_dp1 =
(SELECT sex_code
FROM LU_Sex
WHERE sex_dec = Test.sex_dp1)

I'm guessing this will be the equivalent of what you posted. It will be
so long as sex_dec is unique in LU_Sex and all the values of sex_dp1
also exist in that table.

Presumably you ultimately intend to use one set of codes througout the
database. There is in fact an International standard for gender codes
(0=not known 1=male 2=female 9=not specified). You could also use views
to convert the codes if you need to do so for display for example.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
(me*****@yahoo.com) writes:
I tried to go from this....

SELECT dbo.LU_SEX.SEX_CODE, dbo.TEST.DEFECTS_DP1
FROM dbo.TEST INNER JOIN
dbo.LU_SEX ON dbo.TEST.SEX_DP1 =
dbo.LU_SEX.SEX_DEC

To this...

UPDATE dbo.TEST.SEX_DP1
You have a database dbo with a schmea TEST and table SEX_DP1?
Drop SEX_DP1 to start with.
SET dbo.TEST.SEX_DP1 = dbo.LU_SEX.SEX_CODE
And here drop dbo.TEST on the left-hand side. You can uses prefixes on
the left-hand side, but I don't recall under which circumstances. In any
case, since you can only update one table at a time, it's redundant.
FROM dbo.LU_SEX INNER JOIN
dbo.TEST ON dbo.LU_SEX.SEX_DEC =
dbo.TEST.SEX_DP1
This should be fine, although I recommend you to use aliases to make
your queries less verbose.

Maybe I need a good book on this?


Books Online, see signature.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

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

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
2
by: Aussie Rules | last post by:
Hi, I have a site that Iwant to either display my text in english or french, based on the users prefernces ? I am new to webforms, but I know in winforms, this is pretty easy with a resource...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.