Sorta a college alumni - SQL newbie here, Wondering a way to updating 3 items with repeating numbers (triplets), without having to type/change in the ItemIds manually (see example) like 4018, 4019, 4020...etc...etc..Then changing to 4021, 4022, 4023.
update Item
set AltName = SectionSize+'PLN'
where ItemID = 4015
update Item
set AltName = SectionSize+'SRTD'
where ItemID = 4016
update Item
set AltName = SectionSize+'SMTH'
where ItemID = 4017
In that note; Is it easy to add in doubles (ie. odd, even variables) where I can change all the odd numbers or even numbers.. for if I have doubles to change.
Harishgg1 - Yes, I was wondering how easy it would be to do, without having to also change the numbers in the SQL queries.. I'm renaming the part to ' SectionSize' plus adding some verbage (PLN, SRTD, or SMTH)
There are 1,220 rows (basically 4015-5235); And yes, there only be 3, in the order of (PLN, SRTD, SMTH, PLN, SRTD, SMTH, PLN, SRTD, SMTH, PLN, SRTD, SMTH...etc.)
There are 1,220 rows (basically 4015-5235); And yes, there only be 3, in the order of (PLN, SRTD, SMTH, PLN, SRTD, SMTH, PLN, SRTD, SMTH, PLN, SRTD, SMTH...etc.)
create table WhatEver
(
ItemID int ,
SectionSize varchar(100),
AltName varchar(100) null
)
insert into WhatEver select 4015,'1-1 Plain',null
insert into WhatEver select 4016,'1-1 Serated',null
insert into WhatEver select 4017,'1-1 Smooth',null
insert into WhatEver select 4018,'1-2 Plain',null
insert into WhatEver select 4019,'1-2 Serated',null
insert into WhatEver select 4020,'1-2 Smooth',null
insert into WhatEver select 4021,'1-3 Plain',null
insert into WhatEver select 4022,'1-3 Serated',null
insert into WhatEver select 4023,'1-3 Smooth',null
select 'Before Update', * from whatever
UPDATE a
SET a.altname = SectionSize +
CASE WHEN SectionSize LIKE '%Plain%' THEN 'PLN'
WHEN SectionSize LIKE '%Serated%' THEN 'SRTD'
WHEN SectionSize LIKE '%Smooth%' THEN 'SMTH'
END
FROM whatever a
select 'After Update', * from whatever
drop table whatever
UPDATE a
SET a.altname = SectionSize + 'PLN'
FROM whatever a
WHERE SectionSize LIKE '%Plain%'
UPDATE a
SET a.altname = SectionSize + 'SRTD'
FROM whatever a
WHERE SectionSize LIKE '%Serated%'
UPDATE a
SET a.altname = SectionSize + 'SMTH'
FROM whatever a
WHERE SectionSize LIKE '%Smooth%'
no, that is just a sample of your data. in order to provide you with a solution we need to emulate locally on our sql server your data since we do not have access to your sql server. it is just sample data