By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

Need help in writing a Stored Procedure

P: 2
Hi Everybody,

I am trying to update a column Percentage in a table named Critical Doctors with the 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.

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 I can equate the percentage column with one value and also check the condition with one value.

Thanking you guys in advance.

madhav
Mar 29 '07 #1
Share this Question
Share on Google+
4 Replies


P: 12
Hi

Try this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE CriticalDoctors SET CD.Percentage = TP.PercentTime
  2. FROM CriticalDoctors CD, tblPercent TP
  3. WHERE CD.Doctor = TP.DoctorID
  4.  
Mar 29 '07 #2

P: 2
I got the following error

Server: Msg 1032, Level 15, State 1, Line 1
Cannot use the column prefix 'CD'. This must match the object in the UPDATE clause 'CriticalDoctors'.


madhav

Hi

Try this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE CriticalDoctors SET CD.Percentage = TP.PercentTime
  2. FROM CriticalDoctors CD, tblPercent TP
  3. WHERE CD.Doctor = TP.DoctorID
  4.  
Mar 29 '07 #3

iburyak
Expert 100+
P: 1,017
TRy this:

[PHP]
UPDATE CriticalDoctors SET Percentage = TP.PercentTime
FROM CriticalDoctors CD, tblPercent TP
WHERE CD.Doctor = TP.DoctorID[/PHP]
Mar 29 '07 #4

P: 12
TRy this:

[PHP]
UPDATE CriticalDoctors SET Percentage = TP.PercentTime
FROM CriticalDoctors CD, tblPercent TP
WHERE CD.Doctor = TP.DoctorID[/PHP]
Ya, this is fine
Mar 29 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.