 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 19th, 2007, 09:14 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Udate Query
Hello All
I want to write a query that will update a field "A" based on weather another field "B" contains something in field "C"
Eg:
Valuation_no "B" rate_code_rate "C" origen_rate_code "A"
03710/003.00 2000 02000
03710/003.00 3020 03020
Basically i want to say that if "valuation_no" contains "rate_cade_rate" of 2000 and 3020 then make "origen_rate_code" =02000 where "rate_code_rate" = 2000 and the same for where "rate_code_rate" = 3020 make "origen_rate_code" = 03020.
Thanks
|
|

April 22nd, 2007, 03:46 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Thanks for the reply but it did not do as i want (I probably did not explain properly). What I need to do is where a valuation no has a rate_code_rate of 2000 and 3020, then make origen_ _code = 02000 (for rate_code_rate of 2000 and = 03020 (for rate_code_rate of 3020)
Thanks
|
|

April 23rd, 2007, 01:15 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Then try this.
Code:
UPDATE <YourTable>
SET origen_rate_code = RIGHT('00000' + rate_code_rate, 5)
WHERE rate_code_rate in (2000, 3020)
Cheer
_________________________
- Vijay G
Strive for Perfection
|
|

April 23rd, 2007, 03:39 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Vijay
How would I write this query if there were valuation no's that had a rate_code_rate of 1000, 2000 and 3020 but i only wanted to make origen_rate_code = 02000 and 03020 where valuation no only had 2000 and 3020 and not 1000, 2000 and 3020?
Thanks for your reply it did work
Greg
|
|

April 26th, 2007, 09:26 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sorry for the delayed response.
The update statement I posted above does that. It checks only for 2000 and 3020 and updates only those. So I believe it is taken care of.
cheers.
_________________________
- Vijay G
Strive for Perfection
|
|

April 26th, 2007, 09:56 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Vijay
Thanks for the reponce. Your script does work but this is my problem. some valuation no has only got rate_codes of 2000 and 3020 and some have 1000, 2000 and 3020. I only want to change those where a valuation no has 2000 and 3020. here is a copy of my extract
valuation_no rate_code origen_rate_code
03710/001.00 123 1230
03710/001.00 3020 123
03710/001.00 2000 123
03710/001.00 1000 123
03710/002.03 2000 123
03710/002.03 3020 123
03710/002.03 401 4010
03710/002.03 1000 123
03710/003.00 2000 123
03710/003.00 3020 123
Where the origen_rate_code = 123 for valuation no containing 1000,2000,3000 I want to keep but only change to 02000 and 03020 where valuation no only has 2000,3020and not 1000
Thanks
Greg
|
|

April 27th, 2007, 12:24 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Use CASE operator.
|
|

April 27th, 2007, 07:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Try this...
Code:
UPDATE test
SET origen_rate_code = RIGHT('00000' + rate_code_rate, 5)
WHERE valuation_no NOT IN
( SELECT valuation_no FROM test WHERE rate_code_rate IN (1000) )
AND rate_code_rate in (2000, 3020)
Just added the one marked in BLUE
Cheers
_________________________
- Vijay G
Strive for Perfection
|
|

May 2nd, 2007, 03:58 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Vijay this worked. Muck appreciated
Greg
|
|
 |