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
 SQL Server Development (2000)
 Need help in writing a Stored Procedure in MSSQL

Author  Topic 

gmadhava
Starting Member

1 Post

Posted - 2007-03-29 : 07:50:32

Hi Everybody,

I am trying to update a column Percentage in a table named Critical Doctors with a column named PercentTime from tblPercent table, Where the column Doctor matches with any DoctorId from tblPercent.

I am getting an error message for the following query.

Have Two tables

1.CriticalDoctors
2.tblPercent

update CriticalDoctors set Percentage =
(select PercentTime from tblPercent)
where CriticalDoctors.Doctor = (select DoctorId from tblPercent)

Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

Pls give me reply on how to write a stored procedure so that I can equate the percentage column with one value and also check the condition with one value.

Thanking you guys in advance.
madhav

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-29 : 08:53:28
[code]update cd
set Percentage = p.PercentTime
From CriticalDoctors cd Join tblPercent p
on cd.Doctor = p.DoctorId[/code]

1. For performance reason, you should avoid using subquery as far as possible, especially correlated one (use joins over subquery)

2. Use IN operator when you want to compare a column against list of values or when multiple values returned by subquery

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2007-04-02 : 22:59:09
I don't think so.... an inner join is much more effective than a WHERE IN...

--Jeff Moden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-02 : 23:51:12
Also Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Madhivanan

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

- Advertisement -