Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mhr1971
Starting Member
1 Post |
Posted - 2004-03-05 : 16:52:30
|
| I have a table that has a Fantype field including other fields with data and two of the Fantypes areCACABDI need to add two new fans TPD & TPB these fan types are the same asCA and data = TPD and same dataCABD and data = TPB and same dataI want to add the new fans but use the same data that is associated with the CA and CABDI need to have in one table the CA CABD TPD TPB in one table and have the CA & TPD, CABD & TPB have the same data.???????????????????????????????????????? Not sure how to get this part done I need to CREATE TABLE TEMP AND IMPORT STRUCTURE FROM TABLE1 INTO TABLE TEMP.Am I going about this wrong.????????????????????????????????????????----------------------------------------SELECT * INTO TEMP FROM TABLE1DELETE FROM TEMPWHERE FanType <> 'CA' AND FanType <>'CABD';UPDATE TEMP SET FanType = 'TPD'WHERE FanType = 'CA';UPDATE TEMP SET FanType = 'TPB'WHERE FanType = 'CABD';------------------------------------------????????????????????????????????????????????????I'm not sure if this is correctSELECT * INTO TABLE1 FROM (SELECT * FROM TABLE1UNIONSELECT * FROM TEMP);????????????????????????????????????????????????--------------------------------------UPDATE TABLE1 SET LISTPRICE = LISTPRICE * .92;----------------------------------------???????????????????????????????????????????????????Need to replace the first value of 1 in a field andreplace it with a 2. (like 1023 would now be 2023)???????????????????????????????????????????????????? |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-03-05 : 19:02:23
|
| [code]--This is an example of your existing table and datacreate table fans (fantype varchar(5), listprice int, someotherdata varchar(8))insert into fansselect 'CA', 100, 'DATA1' union allselect 'BA', 100, 'DATA3' union allselect 'DA', 100, 'DATA4' union allselect 'CABD', 200, 'DATA2'--before insertselect * from fans--insert the new recordsinsert fansselect case when fantype = 'CA' then 'TPD' when fantype = 'CABD' then 'TPB' end fantype, listprice, someotherdata from fanswhere fantype in ('CA','CABD')--after insertselect * from fansdrop table fans[/code] |
 |
|
|
|
|
|
|
|