Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2007, 11:08 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Update Query

Hi,

I have a further problem....

Using SQL 2000, Query Analyser.

There are 2 tables (MER_Product AND tomtest).
I need to append a value to dbo.MER_Product.Product_Sub_Group_ID depending on a match between a field on each table (dbo.MER_Product.Product_Reference = dbo.tomtest.Code) AND where
dbo.MER_Product.[Product Sub-Group] is equal to a specified value.

There are 95 values to set!

In both examples, if dbo.MER_Product.[Product Sub-Group] = 'En' Then
dbo.[Product Sub-Group] = 1

I've tried this...

Code:
UPDATE dbo.MER_Product
SET Product_Sub_Group_ID = '1'
WHERE dbo.MER_Product.Product_Reference =  dbo.tomtest.Code AND dbo.[Product Sub-Group] = 'En'
Error is "Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'dbo.tomtest' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo' does not match with a table name or alias name used in the query."


And this...

Code:
INSERT INTO dbo.MER_Product
(
Product_Sub_Group_ID
)
WHERE dbo.MER_Product.Product_Reference = dbo.tomtest.Code
SELECT 
CASE dbo.tomtest.[Product Sub-Group]
WHEN 'EN'  THEN '1'
WHEN 'Ar' THEN '2'
END
Error is "Server: Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'WHERE'."

Any help please?

Thanks in advance,



Neal

A Northern Soul
__________________
Neal

A Northern Soul
 
Old April 19th, 2007, 11:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Neal
 
Code:
UPDATE dbo.MER_Product
Code:
SET Product_Sub_Group_ID = '1'
WHERE dbo.MER_Product.Product_Reference =  dbo.tomtest.Code AND dbo.[Product Sub-Group] = 'En'
Error is "Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'dbo.tomtest' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'dbo' does not match with a table name or alias name used in the query."
And this...
You are missing FROM clause there
Code:
UPDATE dbo.MER_Product
SET Product_Sub_Group_ID = '1'
FROM dbo.MER_Product, dbo.tomtest.Code
WHERE dbo.MER_Product.Product_Reference =  dbo.tomtest.Code AND dbo.[Product Sub-Group] = 'En'
Quote:
quote:Originally posted by Neal
 
Code:
INSERT INTO dbo.MER_Product
Code:
(
Product_Sub_Group_ID
)
WHERE dbo.MER_Product.Product_Reference = dbo.tomtest.Code
SELECT 
CASE dbo.tomtest.[Product Sub-Group]
WHEN 'EN'  THEN '1'
WHEN 'Ar' THEN '2'
END
Error is "Server: Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'WHERE'."
check the INSERT syntax on BOL. You can't specify WHERE clause in INSERT.

cheers

_________________________
- Vijay G
Strive for Perfection
 
Old April 19th, 2007, 12:03 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Vijay,

Yet again you come to my aid (I was close but not close enough in my first example).

Many thanks

Neal

A Northern Soul





Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Query Help dalezjc Classic ASP Basics 8 March 18th, 2008 08:49 AM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Update query trab Access 1 May 11th, 2006 03:58 PM
Please Help me about UPDATE query huyremy VB Databases Basics 8 September 29th, 2004 03:45 AM
Update query edcaru Access 3 June 14th, 2004 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.