dbTalk Databases Forums  

Update SQL 2000 Query (converting an Old Access 2k query to SQL)

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Update SQL 2000 Query (converting an Old Access 2k query to SQL) in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ILCSP@NETZERO.NET
 
Posts: n/a

Default Update SQL 2000 Query (converting an Old Access 2k query to SQL) - 03-30-2006 , 12:01 PM






Hello, I have the following query in Access 2000 that I need to convert
to SQL 2000:

UPDATE tblShoes, tblBoxes
SET tblShoes.Laces1 = Null
WHERE (((tblShoes.ShoesID)=Int([tblBoxes].[ShoesID])) AND
((tblBoxes.Code8)="A" Or (tblBoxes.Code8)="B"))
WITH OWNERACCESS OPTION;


The ShoesID in the tblShoes table is an autonumber, however the records
in the tblBoxes have the ShoesID converted to text.

This query runs ok in Access, but when I try to run it in the SQL
Server 2000 Query Analizer I get errors because of the comma in the
"UPDATE tblShoes, tblBoxes" part. I only need to update the tblShoes
field named Laces1 to NULL for every record matching the ones in the
tblBoxes that are marked with an "A" or an "B" in the tblBoxes.Code8
field.

Any help would be greatly appreciated.

JR


Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: Update SQL 2000 Query (converting an Old Access 2k query to SQL) - 03-30-2006 , 02:30 PM






ILCSP (AT) NETZERO (DOT) NET wrote:
Quote:
Hello, I have the following query in Access 2000 that I need to convert
to SQL 2000:

UPDATE tblShoes, tblBoxes
SET tblShoes.Laces1 = Null
WHERE (((tblShoes.ShoesID)=Int([tblBoxes].[ShoesID])) AND
((tblBoxes.Code8)="A" Or (tblBoxes.Code8)="B"))
WITH OWNERACCESS OPTION;


The ShoesID in the tblShoes table is an autonumber, however the records
in the tblBoxes have the ShoesID converted to text.

Try:

UPDATE tblShoes
SET laces1 = NULL
WHERE EXISTS
(SELECT *
FROM tblboxes AS B
WHERE CAST(B.shoesid AS INT) = tblShoes.shoesid
AND B.code8 IN ('A','B')) ;

(untested)

You can find the full syntax and examples of the UPDATE statement in
SQL Server Books Online.

--
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/m...S,SQL.90).aspx
--



Reply With Quote
  #3  
Old   
ILCSP@NETZERO.NET
 
Posts: n/a

Default Re: Update SQL 2000 Query (converting an Old Access 2k query to SQL) - 03-30-2006 , 03:04 PM



Hello David, the code does works. I tested it and it does set to NULL
those fields. Thanks.


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.