Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help on UPDATE and INSERT subquery

Author  Topic 

jamonakes
Starting Member

18 Posts

Posted - 2005-06-20 : 07:58:36
I want to be updating the value of a certain column cell by incrementing the value by 1 everytime a certain condition is fulfilled. This is my SQL statement:

INSERT INTO tblArtists(tblArtists.artVote) Values(SELECT MAX(IsNull(tblArtists.artVote,0) + 1) AS artVote FROM tblArtists WHERE tblArtists.artLinkID = 'a' AND tblArtists.artGenreID =25)

When I do this I get the following error message:
Server: Msg 1046, Level 15, State 1, Line 1
Subqueries are not allowed in this context. Only scalar expressions are allowed.


The example above is on INSERT. I would like someone to help on this and also, more importantly, on an update for the similar example above.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-20 : 08:02:49
Try this
INSERT INTO tblArtists(tblArtists.artVote) 
SELECT MAX(IsNull(tblArtists.artVote,0) + 1) AS artVote FROM tblArtists
WHERE tblArtists.artLinkID = 'a' AND tblArtists.artGenreID =25


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jamonakes
Starting Member

18 Posts

Posted - 2005-06-20 : 09:12:28
Thanks a million, it works. I even got to tweak the code for the update statement. Thanks once again.
Go to Top of Page
   

- Advertisement -