.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using Cursors to bring one table's rows into another table's columns.

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :Sql Server


i have 2 tables; the first one records information about shapes. this table has 3 fields where the primary key is a composite one with the shapeID and DimensionName. 

one shape has 3 records in this table since there can only be 3 values as DimensionName for a given shape (weight, price and color)


the second table has the shape ID , weight, price and color as its columns. where the shapeID is the primary key.


now what i need to do is i need to map the first table's 3 columns in to 1 column of the second table. i am allowed to use cursors for this.


can anyone please explain how can a approach thisproblem?? code snippets are warmly welcomed. :)


please referr the image for further clarification. to view the image, click this link http://i53.tinypic.com/2rcal2x.png


thanks in advance


View Complete Post

More Related Resource Links

updating multiple rows for multiple columns of the table from other table



I have source table called customer. And data from this table is transfered to another database  with same table name.

that is database1(customer table) ----> database 2(customer table)

now in database 2, First time my program runs and it randomly get any name and ssn and then updates the first name, last name, ssn of all the customer_ID's in the customer table (I use RAND function)

Now second when i run the program, it recreates the name and ssn again but different, for the same customer_id.

So i want that once the particular customer_ID is updated, next time if i run the program. it shold not update the those updated customer id's

Thanks, Any help is appreciated.


Dataset has one field, populate a table 2 columns wide n rows deep



A dataset returns a single field of child names, instead of presenting this as a single column table, I would like it to be multi column.

Dataset returns:


I would like to display it as:

Child1 Child2 
Child3 Child4


Using jQuery to Filter Table Rows

The project is using the .net GridView control, so I had limited control over the output HTML code. Still, I think this code can work for most tables. One thing to notice: you should use the class "filterable" on your table or on one of its parents for the code to work.
First, we need a text box:

RadioButton Groups, Table Rows And NamingContainers in asp.net

The RadioButtonList. Very handy for inviting users to select just one item from a list although because of the screen real estate it takes up, used less and less in favour of the DropDownList. In plain HTML, the browser knows to enforce the unique selected value amongst a list of radio buttons because they all have the same value for their name attributes.

RadioButton Groups, Table Rows And NamingContainers

(In which AJAX-enhanced CheckBoxes become more useful than RadioButtons but inheritance saves the day, and a simple RadioButton-derived control establishes the purpose of a control's naming container)

The RadioButtonList. Very handy for inviting users to select just one item from a list although because of the screen real estate it takes up, used less and less in favour of the DropDownList. In plain HTML, the browser knows to enforce the unique selected value amongst a list of radio buttons because they all have the same value for their name attributes.

Entity Data Model and database view returning the same columns as there are in a table


When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined. 

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.

var foos = myDB.FilteredFoos.Include("Bar").ToList();

foreach (Foo foo in foos) { ...

Thanks, Jenda

How to create scrolling table for columns in a SharePoint Designer Data View


I have a fairly complex SharePoint Designer 2007 Data View they have added two more requirements.

1. Have the columns on the right side be able to scroll left to right as there is a large number of columns, while the first 3 columns on the left side stay locked in place.  This is only one list not two, and because of some other requirements I have it must remain to be just one list.

2. Then they also need to have scrolling up and down of the entire list with the headers locked in place.

The first requirement is more important than the second, but preferrably I need to do both.

I am new to XSL so not familar with the syntax. Is this something I can do on a custom Data View? Does anyone have any examples of how?

I have a drawing that show how it needs to look but I don't see an option here to upload a graphic.

So here is a link to my graphic example uploaded to my blog area: http://lindachapman.blogspot.com/  or just the image here: http://4.bp.blogspot.com/_aB01ue__NvQ/TGL42MOvrGI/AAAAAAAAAA4/c3xP4uCy4BU/s1600/Scrolling.png

I failed to mention that 3/4 of the columns are HTML Calculated fields wh

SMO classes to generate alter table script to add columns

How to generate ALTER TABLE script to add columns using SMO and c#.

no of rows in single table

hi friends...i need one count...one sql table how many rows able to create or write in sql server 2005

How to get the Top N rows from SQL Table..

Hello Friends..                 Recently i have come across one question in sql queryQuestion:         Which SQL Query helps to view the TOP N rows From the particular SQL table?I request anyone please solve this question... Thanks...                   

Computed Columns in Table Variables or Table Types

I was just looking for confirmation that computed columns can or cannot be used in a @Table Variable or User-Defined Table Type. I'm trying this: declare @testtable as table(  [testcol] as case when [testcol] = '' then 'a' else 'b' end,  [testcol2] varchar(100) ); insert into @testtable select '','someval' insert into @testtable select 'c','someval2' select * from @testtable It all parses fine, but during the first insert an error is returned Msg 402, Level 16, State 1, Line 2 The data types void type and varchar are incompatible in the equal to operator. Thank you, Paul

Mark columns as Identity in multi-table views?

Hello! When you create a view of one table (i.e. SELECT * FROM Table), it marks the table's identity column as an identity col in the view as well. I have a few that selects columns from several nested tables, but they are all related in a main identity column I select as well, but SQL Server doesn't mark this column as identity, is there a way to do it?Shimmy

Duplicate rows in Table

Hi, I have a table with two rows Name  ||    Surname || Account No || Money Expensise || Amount                                                     Total ------------ Amount How can I display the last row Total at the bottom of the table not for every first row.  Thanks Anyone helps!

generate dinamic rows with tetxbox in asp:table

) dynamically generated new rows containing two columns, one with a display name and the other a textbox for the user to enter a value. " ye="Hola, en TablaVenta () genero dinamicamente nuevas filas que contienen dos columnas una con un nombre para mostrar y la otra un textbox para que el usuario ingrese un valor." closure_uid_83htk5="176" mce_style="BACKGROUND-COLOR: #ebeff9">Hello, in TablaVenta (<asp:table>) dynamically generated new rows containing two columns, one with a display name and the other a textbox for the user to enter a value.When I want to retrieve those rows from the code, I notice that there are no rows created in the tableList<BLL.Producto> productos = new List<BLL.Producto>(); for (int i = 0; i <= TablaVenta.Rows.Count; i++) { TableRow tr = new TableRow(); tr = (TableRow)TablaVenta.Rows[i]; for (int c = 1; c <= tr.Cells.Count; i++) { BLL.Producto unProd = new BLL.Producto(); unProd.Nombre = TablaVenta.Rows[i].Cells[c].Text;   Error: Specified argument was out of the range of valid values.Parameter name: index Do you know, what i can will do? Thankss

Want to show FormView in Edit mode with specific table columns depending on their Genre??

hi, I have  a table in my database called "Profiles". This holds data on Female and Male personal characteristics. On my aspx, I have a formview in edit mode which is binded to an object data source with a GetDataByUserId Select method which retrieves data from the "Profiles" Table via a DAL. The "Profiles" table has some columns which relates to females only and some just males and some are generic to both. See example below     UserId - / of Type GUID GenreId /  of Type BOOL. Hip Size (For females) Dress Size ( For Females) ChestSize (For Men ) TrouserSize (For Men) Weight ( For both )   When the User logs in , they go to an update Page which has the Formview in Edit Item Mode and contains drop down Lists which are binded to the Users Selected Value. The DDL are in turn bound to their related table such as HIP, Dress, Chest, Trouser etc. Objective If a female user logs in I just want to show them the (Hip Size) DDL  and DressSizeDDL in the Edit item template of the formview and not the ChestSize DDL or  TrouserSize DDL. At present the GetProfileByUserId returns all colums from the table My question is how do I do this and just show DDL which are relevant to the Female or Male Only. In some cases the user may not have selected an item in the previous form so they could also be

How to get column value difference of rows in same table

Dear all, I need a TSQL statement to find the difference of values of two rows in the same table, by taking into consideration some conditions. I have the following rowss in a table named table1 dbname  sqlinst     size1   ddate sqldb1    inst1        200    1/1/2009 sqldb1    inst1        250    1/1/2010 sqldb1    inst1        170    1/1/2008 sqldb2    inst2        300    1/1/2009 sqldb2    inst2        340    1/1/2010 I need to find the difference between size1 values, for columns where their dbname and sqlinst are the same. I also need to define in TSQL that the ddate of row from where I subtract (size1) from is 1/1/2010 and that the ddate of the row I subtract (size1) is 1/1/2009 (e.g. in the above example: for sqldb1 inst1, I need to perform 250-200 and ignore 170, and for sqldb2 inst2  340-300). Please let me know if you have a solution for this. A million thanks!

How to declare a table variable in SSIS and then insert rows into it

Hello everyone,   I'll try to explain my problem as clearly as I can: 1)I have an Execute SQL Task that's inside a Foreach Loop Container. 2)Inside the Execute SQL Task, I have an int OUTPUT column. 3)With each iteration, I need to insert the data from the INT output colum into a table variable. 4)After the Foreach Loop finishes the iterations, I need to use the table variable to create a report based on the data inside.   My question is the following: How can I declare a table variable so that I can do all of the above?   Thank you, CostinP
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend