Computing.Net > Forums > Database > Update query problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Update query problem

Reply to Message Icon

Name: gilbe73
Date: April 14, 2009 at 10:51:22 Pacific
OS: Windows XP
Subcategory: MS SQL Server
Comment:

Hello,

here is my short script in sql server 2000:

[b]Create Table #tmp(ID int,y_val char(30),...)
Insert Into #tmp
exec stored_procedure[/b]

now my #tmp is filled with [u]214[/u] rows,
87 of them have the same ID value(when I use distinct x_val
on #tmp I get [u]87[/u] rows)

my next step is to try to update another table for each row([u]214[/u] times)I have in the temporary table:

[b]Update x_table
set field_x =
Case When m1.ID is null Then m2.x_val
Else m1.ID + ',' + m2.x_val End
From x_table m1
Inner join #tmp m2
where m1.ID= m2.ID[/b]

My problem is that the update action seems to run only 87 times and not 214 times as the number of rows in the #tmp table.

The m1.ID should have a value like this in the end: 25,27,30... for the rows with ID that exist more then once.

maybe this is more clearly sample:

#tmp table has rows like this:

[u]ID[/u] [u]val_1[/u] [u]val_2[/u]
1 25 26
1 42 31
2 55 25
3 60 30


Second table has this row:
[u]ID[/u] [u]val_1[/u] [u]val_2[/u]
1 42 31
2 55 25
3 60 30

I want the update action run 4 times as the number of rows in the #tmp
so row with ID 1 in the second table will be update twice.


Thanks for your help, Gil



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Output File - Header Remo... Excel Formula I can't fig...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Update query problem

Update query shift down by 1 www.computing.net/answers/dbase/update-query-shift-down-by-1/377.html

Access Query question www.computing.net/answers/dbase/access-query-question/606.html

ACCESS Record Merge www.computing.net/answers/dbase/access-record-merge/293.html