 |
| 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
|
|
|
|

November 17th, 2004, 11:39 AM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Stored Proc. problem - newbie
Hi,
I've just started writing some stored procedures to optimize some things on my database, but it seems I got some syntax wrong. Would you mind having a look on the code:
Code:
CREATE PROCEDURE cp_procedure
AS
SELECT A.a, A.b, A.c, A.d, B.a
FROM A LEFT JOIN B ON (A.b = B.a)
SET A.a = False
SET A.b = 9999
SET A.c = [Amount]
WHERE (A.d)='F')
AND (B.a) IS NULL
GO
|
|

November 17th, 2004, 12:28 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You have an extra ) in the WHERE clause.
|
|

November 17th, 2004, 01:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Your select and your update are separate operations, you need to specify the table used in the update part.
--
Joe ( Microsoft MVP - XML)
|
|

November 18th, 2004, 06:34 AM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the input. The extra ) was an mistype :O)
I introduced the UPDATE but still get an error in line 8 (incorrect syntax near '.'). Am I'm missing something obvious here?
Code:
CREATE PROCEDURE cp_procedure
AS
SELECT A.a, A.b, A.c, A.d, B.a
FROM A LEFT JOIN B ON (A.b = B.a)
UPDATE A
SET A.a = False
SET A.b = 9999 -- What is wrong in this line 8?
SET A.c = [Amount]
WHERE (A.d)='F'
AND (B.a) IS NULL
GO
|
|

November 18th, 2004, 08:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
If this is SQL Server then False is not valid, you normally use 1 and 0 in a bit field for true/false. You also need commas separating the individual SET parts:
Code:
UPDATE A
SET A.a = 0,
SET A.b = 9999,
SET A.c = [Amount]
WHERE (A.d)='F'
AND (B.a) IS NULL
You also have not included B in the update line. Your original SELECT is totally separate from your update.
--
Joe ( Microsoft MVP - XML)
|
|

November 22nd, 2004, 06:18 AM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for helping me put here...
I've tried to rewrite it:
Code:
UPDATE A
SET A.a = 0, A.b = 9999, A.c = A.d
WHERE(
SELECT A.a, A.b, A.c, A.d, B.a
FROM A
LEFT JOIN B ON
A.b = B.a
WHERE (A.c = 'F') AND (B.a IS NULL)
)
Still no go... damn.
|
|
 |