SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help with a query please


Need help with a query please

Author
Message
Dominic Gagné
Dominic Gagné
SSC-Addicted
SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)

Group: General Forum Members
Points: 499 Visits: 320
ID lotCode lotCurrentQty lotNetWeight NbPal spCode
64 0113047522003 0 0 0 NULL
10 0113047522003 16 516 1 SP0113000033
11 0113047522003 14 457 1 SP0113000034
65 0113047522004 0 0 0 NULL
12 0113047522004 19 480 1 SP0113000033
13 0113047522004 21 526 1 SP0113000034
19 0113047522004 29 670 1 SP0113000034

let's assume this recordset as an example. I need to update the fields lotCurrentQty, lotNetWeight and NbPal to zero for all the other instances of spCode, but the first one. In this case, row ID 12 (related to row ID 10) and row ID 13 and 19 (related to row 11) should be update to 0. How can I do that??

It's a SQL 2000.

thanks a lot for your time and help
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63398 Visits: 17966
In order to help we will need a few things:

1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data

Please take a few minutes and read the first article in my signature for best practices when posting questions.

Also, you said something about the "first" one. There is no concept of order in a table. If you want an order you have to define it. That means there must be something to order by.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
sharath.chalamgari
sharath.chalamgari
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2002 Visits: 798
Just check if you are looking some thing like this Query,


update testtable1
set lotCurrentQty = 0,
lotNetWeight = 0 ,
NbPal = 0
where id not in (
Select * from testtable1
where spcode is not null
group by spCode)




But Please do prepare some DDL and INSERT statements as Sean Lange mentioned, will help us to help you.
Dominic Gagné
Dominic Gagné
SSC-Addicted
SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)SSC-Addicted (499 reputation)

Group: General Forum Members
Points: 499 Visits: 320
yeah, it's something like that! I'll work around that! thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search