473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sorting x amount of rows into columns

I have a table called cabledrum
It has the following columns
DRUM COND1 COND2 COND3 COND4 COND5
Drum1 NEW DRUM: 14.2392m
Drum10 EP-55306R2-2: 15.9850m
Drum11 REV_B CABLE001: 12.3789m REV_B CABLE002: 12.3789m REV_B CABLE003: 12.3789m REV_B CABLE004: 12.3789m
Drum2 EC-09302: 22.7382m C1: 3.4078m C2: 3.4078m C3: 3.4078m
Drum3 CABLE001: 6.3839m
Drum4 EC-55306: 19.1384m
Drum5 EXTRATEST: 14.2744m
Drum6 EP-55306R2-1: 15.9787m
Drum7 EP-55306R1: 14.2744m
Drum8 ANOTHER: 22.6118m EP-09400: 22.2079m AATAKE2: 14.3743m AFTER: 14.3743m EP-55306R3: 14.2744m
Drum9 EP-55306: 12.0687m

I want to sort this so it is in the format as:

DRUM Cable Tag
Drum1 NEW DRUM
Drum10 EP-55306R2-2
Drum11 REV_B CABLE001
Drum11 REV_B CABLE002
Drum11 REV_B CABLE003
Drum11 REV_B CABLE004
Drum2 EC-09302
Drum2 C1
Drum2 C2
Drum2 C3
Drum3 CABLE001
Drum4 EC-55306
Drum5 EXTRATEST
Drum6 EP-55306R2-1
Drum7 EP-55306R1
Drum8 ANOTHER
Drum8 EP-09400
Drum8 AATAKE2
Drum8 AFTER
Drum8 EP-55306R3
Drum9 EP-55306

I have been able to do this using Left function, SQL Union Select and build table queries
I also have it starting automatically with an AutoExec Macro
The problem I have is the CONDx column is not always 4 columns it can be 100+ columns
This requires me to look at how many CONDx columns there are and write a Left function query for each column
Is there a was where I do this without already knowing the number of condx
Thankyou for you help
i have written this out in txt file incase the columns don't line up
Attached Files
File Type: txt table.txt (1.5 KB, 378 views)
Nov 25 '10 #1
1 1237
TheSmileyCoder
2,322 Expert Mod 2GB
What you should have is a one-to-many relationship between your information. That is one primary record (drum) can have many related secondary records (conditions)

tbl_Drum containing the drum(s) with fields such as:
Expand|Select|Wrap|Line Numbers
  1. KEY_Drum    (Primary Key, I'd suggest autonumber)
  2. tx_DrumName (Text field)
tbl_DrumCond:
Expand|Select|Wrap|Line Numbers
  1. KEY_Cond (Primary Key, I'd suggest autonumber)
  2. ID_Drum  (Foreign key, with ID of drum)
  3. tx_Cond  (Text field, name of the condition)
  4. int_m    (Integer field, with length in m's)
With this setup, you can make acheive what you want. It is also the Best Practice/standard way of using relational databases. You can create queries, where you now include both tables, joined by the drum ID, sorting by the drum name, which would look like what your asking for.
Nov 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric | last post by:
please help to select these rows from these tables my tables are table1 table1Id groupId table2id price 1 1 1 10 2 1 3 1000 3 1 ...
2
by: Gaurav Gargate | last post by:
To Group, I am creating a datagrid in an ASP.NET project (C#) at the design time. I will be adding the columns to the datagird at run time. The number of columns, name of the columns, data in...
1
by: Slonocode | last post by:
I have a form with some textboxes, checkboxes, and comboboxes that are databound to the "Packages" table in a dataset. For Example: Me.txtFirstName.DataBindings.Add(New Binding("Text", DS,...
0
by: Dorte | last post by:
Hi, I use the gridview control to display data. I use a dataadapter to fill a datatable from an SQL server - the command is a stored procedure. Furthermore I have a couple of template columns...
2
by: J055 | last post by:
Hi I've been looking into different ways of formatting columns/rows in the GridView control. I realize now, I think, that once the datasource is bound to the control the original column type...
2
by: sivagururaja | last post by:
Hi All, How can i sorting the Gridview Columns via the code behind. When i tried to sorting the column it doesn't work. SqlConnection con = new SqlConnection("Connection string");...
0
by: yoav.sagi | last post by:
hi, i am Inheriting from TableLayoutPane with a designer that inherits from ParentControlDesigner ..i would like to allow the user to resize the columns and rows ..All rows and columns SizeType =...
6
by: viki1967 | last post by:
Hi all. I need your help. I realize this script and I do not know where to begin: 1) A simple grid rows / columns. 2) The first column contain an input type = "checkbox" 3) When select...
3
by: ronakinuk | last post by:
how can i unhide rows/columns in excel 2007
1
by: nawedita | last post by:
Hi everyone how i add and delete rows,and columns(textbox,dropdown) dynamically onclick button and store data in database with insert,update,delete record.that support all browsers.Because i am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.