Author |
Topic |
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 06:51:06
|
hihow can i insert two record and change the valueeg i have 500 recordscol1 col2abc 101 def 201ghi 301till 500 recordsi need to insert col1 col2abc 101 abc 102 abc 103def 201def 202def 203ghi 301ghi 302ghi 303thanxscoorgi |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 06:53:12
|
Will you try to explain a little more? 500 records of what?abc101 to abc600?What happens after ghi?Peter LarssonHelsingborg, Sweden |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 07:00:54
|
or do you mean something like this?declare @test table (original bit, col1 varchar(3), col2 int)insert @test (original, col1, col2)select 1, 'abc', 101 union allselect 1, 'def', 201 union allselect 1, 'ghi', 301select * from @test order by col1, col2insert @test (col1, col2)select t1.col1, t2.col2from @test t1cross join @test t2left join @test t on t.col1 = t1.col1 and t.col2 = t2.col2where t.col1 is nullselect * from @test order by col1, col2 Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 07:06:27
|
hipeter i should thank u for sloving my pervious queryoksee i have 500 recordssay table carcolumn1 column2abc 101 def 201ghi 301........zzz 999500 rows selectedin the tablei need to insert record after each or one row/record say abc 101 to abc 101,abc 102,abc 103 then def 201 to def 201,def 202,def 201 then ghi 301 to ghi 301,ghi 302,ghi 303 till the end of the record zzz 999,zzz 1000,zzz 1001thanxscoorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 07:09:12
|
You still is not clear what happens after ghi. Does jkl come after that?Or after ghi303 it is zzz101?Peter LarssonHelsingborg, Sweden |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 07:12:08
|
Something like this?declare @test table (original bit, col1 varchar(3), col2 int)insert @test (original, col1, col2)select 1, 'abc', 101 union allselect 1, 'def', 201 union allselect 1, 'zzz', 999 union allselect 1, 'ghi', 301select * from @test order by col1, col2insert @test (col1, col2)select col1, 1 + max(col2)from @testgroup by col1select * from @test order by col1, col2 Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 07:16:34
|
no it will be jkl mno pqr goes on till 500 rowsi ran ur query out put is 1 abc 101NULL abc 201NULL abc 301NULL def 1011 def 201NULL def 301NULL ghi 101NULL ghi 2011 ghi 301i need to get abc 101abc 102abc 103def 201def 202def 203ghi 301ghi 302ghi 303till zzz thanxscoorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 07:24:19
|
Ok, so you have abc, def, ghi. And then jkl, mno, pqr, stu, vwx, yz?DEFINE THE RIGHT ORDER, PLEASE!!!!!!! Do you expect us to read your mind?Also, do you need only three records for each "group"?You have 101-103, 201-203 and 301-303.And then what? 401-403, 501-503, 601-603, 701-703, 801-803, 901-903 and 1001-1003?Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 07:38:11
|
hi peter thanxs its correct changed littledeclare @test table ( col1 varchar(3), col2 int)insert @test (col1, col2)select 'abc', 101 union allselect 'def', 201 union allselect 'zzz', 999 union allselect 'ghi', 301select * from @test order by col1, col2insert @test (col1, col2)select col1, 1 + max(col2)from @testgroup by col1insert @test (col1, col2)select col1, 1 + max(col2)from @testgroup by col1select * from @test order by col1, col2out put is abc 101abc 102abc 103def 201def 202def 203ghi 301ghi 302ghi 303zzz 999zzz 1000zzz 1001this is correct but one small request peter i will only send column name so that i dont need to put insert @test (col1, col2)select 'abc', 101 union allselect 'def', 201 union allselect 'zzz', 999 union allselect 'ghi', 301for 500 to thousand of recordsthanxs once agincoorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 07:56:03
|
Please!? Why don't you put in a little effort yourself?insert @test (col1, col2)select @colname,1 + max(col2)from @test where col1 = @colname Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 08:47:09
|
declare @test table ( col1 varchar(3), col2 int)declare @colname varchar(8)select * from @test order by col1, col2insert @test (col1, col2)select @colname,1 + max(col2)from @test where col1 = col2insert @test (col1, col2)select @colname,1 + max(col2)from @test where col1 = col2select * from @test order by col1, col2coorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 09:01:13
|
This makes no sense at all!col1 will never be equal to col2. Or?Why aren't you able to understand and listen?Peter LarssonHelsingborg, Sweden |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 09:15:15
|
And most important, why don't you learn?Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 09:15:36
|
one sec i think i posted wrong sorrycoorgi |
 |
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-10-27 : 09:39:54
|
WHY are you doing this?-------Moo. :) |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 09:43:08
|
hisorry peter for miss interpeting some infoi have data col1 col2 col3 col4PM 1 MONTH PLAN FOR IMPORTANT EQPTS CAR11MBH05AC201-M3 11MBH05AC201-M3PM 1 MONTH PLAN FOR IMPORTANT EQPTS CAR11MBH05AC201-F1 11MBH05AC201-F1PM 1 MONTH PLAN FOR IMPORTANT EQPTS CAR11MBH05AC201-F2 11MBH05AC201-F2PM 1 MONTH PLAN FOR IMPORTANT EQPTS CAR11MBH05AC201-F3 11MBH05AC201-F3PM 1 MONTH PLAN FOR CRITICAL EQPTS CAR11MBV01AP401 11MBV01AP401PM 1 MONTH PLAN FOR CRITICAL EQPTS CAR11MAY02AA151 11MAY02AA151PM 1 MONTH PLAN FOR CRITICAL EQPTS CAR11MAY02AA152 11MAY02AA152PM 1 MONTH PLAN FOR CRITICAL EQPTS CAR11MBV01AP401 11MBV01AP401i need to INSERT col3 only for first 5 charcters eg CAR11MBH05AC201-M3 TO CAR11MBH05AC201-M3,CAR12MBH05AC201-M3,CAR13MBH05AC201-M3FOR Functional location COLUMN coorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 09:49:58
|
You really, really, really need to normalize your database data.Peter LarssonHelsingborg, Sweden |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 09:56:00
|
[code]declare @test table (col1 varchar(4), col2 varchar(30), col3 varchar(18), col4 varchar(15))insert @testselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-M3', '11MBH05AC201-M3' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F1', '11MBH05AC201-F1' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F2', '11MBH05AC201-F2' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F3', '11MBH05AC201-F3' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MBV01AP401', '11MBV01AP401' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MAY02AA151', '11MAY02AA151' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MAY02AA152', '11MAY02AA152' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MBV01AP401', '11MBV01AP401'select * from @testinsert @testselect col1, col2, car + newserial + oldcol3, newserial + oldcol4from ( select col1, col2, left(col3, 3) car, convert(varchar, 1 + cast(substring(col3, 4, 2) as int)) newserial, substring(col3, 6, 8000) oldcol3, substring(col4, 3, 8000) oldcol4 from @test ) xselect * from @test[/code]Peter LarssonHelsingborg, Sweden |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 09:56:35
|
STRUCTURE OF TABLE CREATE TABLE Criticaland_INportant([F1] [float], [Mainenance Plan category] [nvarchar] (255) , [Maintenace Plan Description] [nvarchar] (255) , [Functional location] [nvarchar] (255) , [Equipment No KKS] [nvarchar] (255) , [Equipment internal number] [nvarchar] (255) , [Tasklist Type] [nvarchar] (255) , [Tasklist Group] [nvarchar] (255) , [Group Counter] [float] , [Maintenance cycle] [nvarchar] (255) , [Cycle Unit] [nvarchar] (255) , [Call horizon] [float] , [Scheduling period] [float], [Unit] [nvarchar] (255) , [Completion Requirement] [nvarchar] (255) , [F16] [nvarchar] (255) )coorgi |
 |
|
oracle_corrgi
Yak Posting Veteran
98 Posts |
Posted - 2006-10-27 : 10:07:19
|
hiInsert query for two one after another two like eg: CAR11MBH05AC201-F2,CAR12MBH05AC201-F2,CAR13MBH05AC201-F2not CAR11MBH05AC201-F2,CAR12MBH05AC201-F2actually it should be 24 recordsthanxscoorgi |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-27 : 10:12:52
|
Here we go again...declare @test table (col1 varchar(4), col2 varchar(30), col3 varchar(18), col4 varchar(15))insert @testselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-M3', '11MBH05AC201-M3' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F1', '11MBH05AC201-F1' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F2', '11MBH05AC201-F2' union allselect 'PM 1', 'MONTH PLAN FOR IMPORTANT EQPTS', 'CAR11MBH05AC201-F3', '11MBH05AC201-F3' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MBV01AP401', '11MBV01AP401' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MAY02AA151', '11MAY02AA151' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MAY02AA152', '11MAY02AA152' union allselect 'PM 1', 'MONTH PLAN FOR CRITICAL EQPTS', 'CAR11MBV01AP401', '11MBV01AP401'select * from @testinsert @testselect col1, col2, car + newserial + oldcol3, newserial + oldcol4from ( select col1, col2, left(col3, 3) car, convert(varchar, 1 + cast(substring(col3, 4, 2) as int)) newserial, substring(col3, 6, 8000) oldcol3, substring(col4, 3, 8000) oldcol4 from @test ) xinsert @testselect col1, col2, car + newserial + oldcol3, newserial + oldcol4from ( select col1, col2, left(col3, 3) car, convert(varchar, 1 + cast(substring(col3, 4, 2) as int)) newserial, substring(col3, 6, 8000) oldcol3, substring(col4, 3, 8000) oldcol4 from @test ) xselect * from @test Peter LarssonHelsingborg, Sweden |
 |
|
Next Page
|
|
|