473,626 Members | 3,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Foreach Column In Row, Create New Row

233 New Member
I have a recipe table that consists of a recipe id as well as seven column, each of the seven columns consisting of an ingredient. I would like to create a separate row for each column in the row. For example, i currently have:

recipeid,ind1,i nd2,ind3,ind4,i nd5,ind6,ind7

I would like to have:

recipeid,ind1
recipeid,ind2
recipeid,ind3
...

How would I go about this?
May 21 '10 #1
3 2703
ck9663
2,878 Recognized Expert Specialist
Try to UNPIVOT your table.

Happy Coding!!!

~~ CK
May 21 '10 #2
mcfly1204
233 New Member
@ck9663
I am using SQL Server 2000, so the pivot/unpivot commands are not available. I am looking into how to accomplish this with union all commands.
May 24 '10 #3
ck9663
2,878 Recognized Expert Specialist
Try doing a cross join.

Happy Coding!!!

~~ CK
May 24 '10 #4

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

Similar topics

4
1987
by: sidd | last post by:
Hi all, please see if some one can suggest a better approach for this. i need to move 5 million rows from one table to another. LoanID is the only clumn in Source table Source table structure =========--> ============================== loanID 1 1
3
2320
by: T Tran via SQLMonster.com | last post by:
Hi Gurus, I'm a beginner. Would you please tell me if it's possible to create a view having a calcuated column based on the condition of the column on the sql table. create view vwImaging AS select EmpID, LastName, FirstName, EmpTag = 'Act' if FROM tblPerPay
3
3221
by: Yeah | last post by:
I have an HTML table with two columns of text. Here's what it looks like: FIRST COLUMN (each cell is ID="date') Background orange, font Serif size 13px, aligned center SECOND COLUMN (each cell is class="entry") Background white with clickable text link (Sans-serif 11px, link black, visited blue, hover navyblue) The first column's content has been assigned CSS ID "date", in the above mentioned style. The second column's content has...
16
2137
by: Josué Maldonado | last post by:
Hello list, The TCL trigger that uses NEW and OLD arrays failed after after I removed a unused column, now I got this error: pltcl: Cache lookup for attribute '........pg.dropped.24........' type 0 failed I already did a vacuum, but the error remain. Any idea how to fix/avoid that?
5
8428
by: Dov Moryusef | last post by:
Hi to all, I’ve a table with an idendity column : CREATE TABLE USRDB2.MYTABLE ( "ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1, NO CACHE), "CODE" CHARACTER (3), PRIMARY KEY (ID))IN MYTS01@
2
4498
by: Laurent | last post by:
DB2 8.1 ------- db2 => create table test (COL1 VARCHAR(10)) db2 => insert into test values ('A') db2 => insert into test values ('A ') db2 => insert into test values ('B') db2 => insert into test values ('B ') db2 => insert into test values ('C') db2 => select distinct COL1, LENGTH(COL1) from test
6
3233
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order entry application. The code below gets line items from a SQL Server database and returns them to a datagrid by way of a DataTable called lineTable. As long as I am just displaying columns in the SQL database everything works well. I now want...
1
1398
by: trint | last post by:
i have a gridview that I want to fill with a combination of sql and strings: foreach (XmlNode rate in rates) { the first column needs to be "/images/ups.gif" every time. the second column, I'll get from sql server with a select. the result will be like "Next Day Air", "2nd Day Air" or something like that. the third column will be the total charges that i have in a string totalCharges.
4
25522
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the columns collection. I modified the RowCreated even to gridview, and I can change properties on the cells, but not width. (setting tooltip, background color, etc, all work but changing width has no effect). Here's sample code I am using:
8
4424
by: xzmilan | last post by:
Totally new to using loop through's but I have a feeling it's what I need. I have two tables tbl1 has a user ID and a change date, a date they updated their information tbl2 has the user ID and an amount they asked to be reimbursed on a specifice date. tbl1 change date is in one column. I want to get the sum of reiembursement from tbl2 but only between the correct date ranges from the column in tbl1.
0
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.