April 25, 2008 at 9:35 am
I need to select records from table A where bspid like '%CI11%' (bspid = 'MHCI111208')
Then I need to insert these same selected records back into table A while
at the same time changing bspid to 'MHCIRC1208'
I have not been able to figure this out yet. Any suggestions would be appreciated.
April 25, 2008 at 9:42 am
Like this?
insert tableA
select col1, col2, col3, ... ,'MHCIRC1208' from tableA where bspid like '%CI11%'
Or is 'MHCIRC1208' derived somehow?
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 25, 2008 at 9:49 am
If you want to insert new records and keep the old then this will work:
[font="Courier New"]SELECT
*
INTO
#data
FROM
tableA
WHERE
bspid LIKE '%CI11%'
INSERT INTO tableA
SELECT
[columns],
'MHCIRC1208' AS bspid
FROM
#data
[/font]
Now if you just want to update the bspid field this is what you want
[font="Courier New"]UPDATE tableA
SET bspid = 'MHCIRC1208'
WHERE
bspid LIKE '%CI11%'
[/font]
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
April 25, 2008 at 9:49 am
RyanRandall (4/25/2008)
Like this?
insert tableA
select col1, col2, col3, ... ,'MHCIRC1208' from tableA where bspid like '%CI11%'
Or is 'MHCIRC1208' derived somehow?
Well you won this time and with a better solution.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
April 25, 2008 at 9:54 am
If you're trying to update a part of the bspid column and maintain other parts of it then you could update like this.
UPDATE TableA
SET bspid= REPLACE(bspid, 'CI11','CIRC')
WHERE bspid LIKE '%CI11%'
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply