Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need help with a query please Expand / Collapse
Author
Message
Posted Wednesday, July 24, 2013 8:08 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 3:48 PM
Points: 130, Visits: 289
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
Post #1477079
Posted Wednesday, July 24, 2013 8:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:17 AM
Points: 13,085, Visits: 12,549
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 Moden's 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)
Post #1477098
Posted Wednesday, July 24, 2013 8:40 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 10:39 AM
Points: 1,194, Visits: 787
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.
Post #1477102
Posted Wednesday, July 24, 2013 9:10 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 3, 2014 3:48 PM
Points: 130, Visits: 289
yeah, it's something like that! I'll work around that! thanks!
Post #1477122
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse