Click here to Skip to main content
15,902,777 members
Home / Discussions / Database
   

Database

 
AnswerRe: Dealing with apostrophe in stored procedure Pin
thatraja12-Apr-11 7:23
professionalthatraja12-Apr-11 7:23 
GeneralRe: Dealing with apostrophe in stored procedure Pin
berba12-Apr-11 21:35
berba12-Apr-11 21:35 
AnswerRe: Dealing with apostrophe in stored procedure Pin
berba12-Apr-11 21:34
berba12-Apr-11 21:34 
GeneralRe: Dealing with apostrophe in stored procedure Pin
berba14-Apr-11 20:38
berba14-Apr-11 20:38 
GeneralRe: Dealing with apostrophe in stored procedure Pin
S Douglas28-Apr-11 11:47
professionalS Douglas28-Apr-11 11:47 
QuestionSSRS Problem [modified] Pin
Kevin Marois10-Apr-11 10:32
professionalKevin Marois10-Apr-11 10:32 
AnswerRe: SSRS Problem Pin
S Douglas13-Apr-11 11:50
professionalS Douglas13-Apr-11 11:50 
Questionrefresh values after each row update [modified] Pin
mersad0010-Apr-11 3:52
mersad0010-Apr-11 3:52 
hi everybody,
I have a big problem with update statement, let me mention the situation by exact script and results!
first create trans table=>
create table trans(
id bigint identity(1,1) not null,
price decimal(18,0) null,
relatedid bigint null)

Then fill it by this script
Insert into trans (price,relatedid)values(100,NULL) 
Insert into trans (price,relatedid)values(100,NULL) 
Insert into trans (price,relatedid)values(500,NULL)
Insert into trans (price,relatedid)values(1,NULL)
Insert into trans (price,relatedid)values(1,3)   


Now run this query!

Update trans
set price=(case when relatedid is null then (select avg(price) from trans where id=<t.id) 
else (select top(1) price from trans where id=t.relatedid) end)
from trans t

After execution of query I expect this result:
id-----price-----relatedid
1 100 NULL
2 300 NULL
3 200 NULL
4 200 3 <======== realy expected!!!!

But this is the result!!!
id-----price-----relatedid
1 100 NULL
2 300 NULL
3 200 NULL <======= #3 row
4 1 3 <===== wrong value, i mean this is the value before update

row with id 3 has been updated before but update doesnt know this!!!!!


WHAT I NEED i need to get expected result from this execution!!!! plzzzzzzzzzzz

modified on Tuesday, April 12, 2011 10:34 AM

AnswerRe: refresh values after each row update Pin
Mycroft Holmes10-Apr-11 4:07
professionalMycroft Holmes10-Apr-11 4:07 
AnswerRe: refresh values after each row update Pin
Wendelius10-Apr-11 5:05
mentorWendelius10-Apr-11 5:05 
GeneralRe: refresh values after each row update Pin
mersad0013-Apr-11 1:06
mersad0013-Apr-11 1:06 
GeneralRe: refresh values after each row update Pin
Wendelius13-Apr-11 5:19
mentorWendelius13-Apr-11 5:19 
Questiondatabase Pin
S.madasamy9-Apr-11 7:49
S.madasamy9-Apr-11 7:49 
AnswerRe: database Pin
Wendelius9-Apr-11 8:05
mentorWendelius9-Apr-11 8:05 
AnswerRe: database Pin
Abhinav S9-Apr-11 23:13
Abhinav S9-Apr-11 23:13 
QuestionCopy Databases objects Pin
vanikanc8-Apr-11 4:07
vanikanc8-Apr-11 4:07 
AnswerRe: Copy Databases objects Pin
Wendelius8-Apr-11 4:19
mentorWendelius8-Apr-11 4:19 
AnswerRe: Copy Databases objects Pin
R. Giskard Reventlov8-Apr-11 4:23
R. Giskard Reventlov8-Apr-11 4:23 
AnswerRe: Copy Databases objects Pin
Corporal Agarn8-Apr-11 6:44
professionalCorporal Agarn8-Apr-11 6:44 
Questionhow can i sort database Pin
ace3008-Apr-11 3:25
ace3008-Apr-11 3:25 
AnswerRe: how can i sort database Pin
Luc Pattyn8-Apr-11 3:43
sitebuilderLuc Pattyn8-Apr-11 3:43 
AnswerRe: how can i sort database Pin
David Mujica8-Apr-11 4:13
David Mujica8-Apr-11 4:13 
AnswerRe: how can i sort database Pin
Ravi Sant14-Apr-11 21:56
Ravi Sant14-Apr-11 21:56 
QuestionAccess / ADO Performance Pin
mjackson117-Apr-11 18:25
mjackson117-Apr-11 18:25 
AnswerRe: Access / ADO Performance Pin
Wendelius7-Apr-11 19:20
mentorWendelius7-Apr-11 19:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.