| Author |
Topic |
|
mberggren
Starting Member
15 Posts |
Posted - 2009-10-21 : 18:00:57
|
Hi,Have a little question. I have a temporary table to store some temporary values that I´m gonna use later on to update other tables. TABLE testnumber INTsub_cat char(16)main_cat char(16) Values in the table now:1, sandals, shoes2, flipflops, shoes3, sneakers, shoes4, no print, t-shirts5, with print, t-shirts6, cartoon, t-shirts Something what I´m looking for:100, shoes101, sandals102, flipflops103, sneakers200, t-shirts201, no print202, with print203, cartoon Is it possible to do this ? Update the 'number' column nr depending of the values in column 'sub_cat' and 'main_cat' .. and then do a UNION on the 'sub_cat' and 'main_cat' column.I guess you first have to do UNION on the 'sub_group' column and then use alter table and delete the 'main_cat' column. Then use row_number with a count and do an update for on 'number' for every 'main_cat' maybe. Insecure how to to it and if I´m thinking right :)As you can see all the 'main_cat' are staring by 100, 200 and so on.////Regards |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-10-21 : 19:06:01
|
quote: Originally posted by mberggrenIs it possible to do this ? Update the 'number' column nr
Paging Nr. Rivett, Mr. Nigel RivettI would ask why you want to do thisIf it's a presentation issue you would do it there.But you probably need to assign a product # to each productI might even have a product table for main_catBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
mberggren
Starting Member
15 Posts |
Posted - 2009-10-22 : 08:38:54
|
Brett:Do you mena something like this ? :)Exampel below.My table1, san_product 1, sandals, shoes2, san_product 2, sandals, shoes3, san_product 3, sandals, shoes4, flip_product 1, flipflops, shoes5, flip_product 2, flipflops, shoes6, flip_product 3, flipflops, shoes7, snea_product 1, sneakers, shoes8, snea_product 2, sneakers, shoes9, snea_product 2, sneakers, shoes10, nop_product 1, no print, t-shirts11, nop_product 2, no print, t-shirts12, nop_product 3, no print, t-shirts13, wit_product 1, with print, t-shirts14, wit_product 2, with print, t-shirts15, wit_product 3, with print, t-shirts16, car_product 1, cartoon, t-shirts17, car_product 2, cartoon, t-shirts18, car_product 3, cartoon, t-shirts wanted result in table100, shoes110, sandals111, san_product 1112, san_product 2113, san_product 3120, flipflops121, flip_product 1122, flip_product 2123, flip_product 3130, sneakers131, snea_product 1132, snea_product 2133, snea_product 3200, t-shirts210, no print211, nop_product 1212, nop_product 2213, nop_product 3220, with print221, wit_product 1222, wit_product 2223, wit_product 3230, cartoon231, car_product 1232, car_product 2233, car_product 3 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-10-22 : 10:01:45
|
How about:SET NOCOUNT ONGOCREATE TABLE #MerchandiceType ( MerchTypeCd int , MerchType char(16) , MerchTypeGroup int , MerchTypeDesc varchar(256))CREATE TABLE #Merchandice ( Merch char(16) , MerchTypeCd char(16) , MerchGroup int , MerchDesc varchar(256))GOINSERT INTO #MerchandiceType ( MerchTypeCd , MerchType , MerchTypeGroup , MerchTypeDesc) SELECT 1, 'Shoes', 10, 'We Sell Shoes' UNION ALL SELECT 2, 'T-Shirst', 20, 'We Sell Tee''s that Don''t Shrink' GOINSERT INTO #Merchandice ( Merch , MerchTypeCd , MerchGroup , MerchDesc) SELECT 'Sandals', 1, 1, 'This is not the resort' UNION ALL SELECT 'FlipFlops', 1, 2, 'This is Georg Bush Sr.' UNION ALL SELECT 'Sneakers', 1, 3, 'This is Slick Willy' UNION ALL SELECT 'No Print', 2, 1, 'This is more a different type than a thing' UNION ALL SELECT 'With Print', 2, 2, 'This is more a different type than a thing 2' UNION ALL SELECT 'Cartoon', 2, 3, 'GW Bush'GOSELECT LEFT(CONVERT(varchar(3),MerchTypeGroup) + '0',3) AS Category , MerchType AS Description FROM #MerchandiceTypeUNION SELECT LEFT(CONVERT(varchar(3),MerchTypeGroup) + CONVERT(varchar(1),MerchGroup),3) AS Category , ' ' + Merch AS Description FROM #Merchandice m JOIN #MerchandiceType t ON m.MerchTypeCd = t.MerchTypeCdORDER BY 1,2DROP TABLE #MerchandiceType, #MerchandiceGOSET NOCOUNT OFFGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
mberggren
Starting Member
15 Posts |
Posted - 2009-10-23 : 04:11:37
|
| Thx a lot! :)See if I get time this weekend to try it out. Give you an reply as soon possible!RegardsMagnus |
 |
|
|
mberggren
Starting Member
15 Posts |
Posted - 2009-11-18 : 07:13:48
|
Brett: That worked great! :)Have a follow up question. I have a table called table1, in this table there are o lot of different columns (seq ,item, main, sub, price, .. etc) all this imported from a excel sheet.From this columns I create different tables for storing information CREATE TABLE custom.main ( Seq int identity main CHAR (50) )CREATE TABLE custom.sub ( Seq int identity sub CHAR (50) )INSERT INTO custom.main (main)SELECT DISTINCT table1.mainFROM custom.table1WHERE table1.main IS NOT NULLINSERT INTO custom.sub (sub)SELECT DISTINCT table1.subFROM custom.table1WHERE table1.sub IS NOT NULL Result of SQLCustom.main1, main12, main23, main3Custom.sub1, sub12, sub23, sub3**So the question is. If I have two tables like in this case. How do I pivot these tables and create a similar result as the previous post ? Add a column called row number in the custom.sub ? This field is gonna generate this below:1000, main11001, sub11002, sub31.., etc….2000, main22001, sub12002, sub32.., etc….Regards |
 |
|
|
|
|
|