x

[Closed] I need serious help in changing the vaue of a column within the same column by going 2 rows up and changing the value

Hello to all,

I am a DBA of 8 months so please bear with me. I am working on this prject for the company I am currently with for the past 4 months and I am almost finished. This is one of the last parts that I need to have functioning. I am needing to write a code that will find a particular ProductIdentifier. When this particular ProductIdentifier is found, 1. I need to grab that ProductIdentifier. 2. I need to go 2 rows up, then place that ProductIdentifier in the field that is 2 rows above it.

Here is my code(everything is sorted properly already in this table)

SELECT SipID,
SaleInvoiceID,
AssociationNumber,
Priority,
TotalPrice,
TotalCost,
SerialNumber,
ContractNumber,
ActivatedThroughPAW,
DateCreatedatMidnight,
ReceivedDate,
InvoiceIDByStore, Location,
ProductIdentifier,
Description,
ShortDescription,
CategoryName,
RevenueStreamID,
RevenueType
FROM REVISEDTABLE.

I will better show you what needs to be done

![alt text][1] [1]: http://ask.sqlservercentral.com/storage/temp/187-picture-of-what-i-need.jpg



What I need for this code to do is this: whenever I find any ProductIdentifier like 'AWRPNS000%', I need for the query to take this and go 2 rows up and replace whatever ProductIdentifier is in this with 'AWRPNS000%'. I then need to insert the results into a table. I believe the best thing to do is to select the ProductIdentifier row again and give it an alias. This will be the row that I need to transform. I can then do a comparison to see if things worked out. A knowledgable SQL user helped me a few days ago with a somewhat diffrent type of solution, but when I tried the same solution with the ProductIdentifier field, I do not get any results. I do not know how to write the code to do the actual grabbing of the ProductIdentifier and going up 2 rows and replacing it. Once again, any help or input would be greatly appreciated. I anyone needs me to add more information please ask.
more ▼

asked May 04, 2012 at 08:52 PM in Default

cdurham gravatar image

cdurham
230 22 22 24

Is there a unique identifier in the table? Possibly SIPID? If so, is that an integer by chance?
May 04, 2012 at 09:07 PM JohnM

@John M

Yes, the unique identifier is the SipID and it is an integer which consists of 5 digits.
May 04, 2012 at 09:35 PM cdurham
(comments are locked)
10|1200 characters needed characters left

The question has been closed May 04, 2012 at 10:14 PM by ThomasRushton for the following reason:

Duplicate of http://ask.sqlservercentral.com/questions/88962/i-need-to-write-a-query-that-will-find-a-certain-v.html

0 answers: sort voted first

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x40
x17

asked: May 04, 2012 at 08:52 PM

Seen: 694 times

Last Updated: May 04, 2012 at 09:35 PM