SQL Server :: Combine Two Rows Of Data?

Mar 9, 2011

have a complex sql stored procedure which involves several unions.The unions also involveat from views. When the data is returned, it might look like the following.

ProductId Name Amount Buyer Date YearsAsCustomer
1 Jones 234.44 Nichols
1 Jones 3/12/2011 3
2 Melon 333.00 Tripol
2 Melon 3/23/2011 4

This is just a simple example, but notice how the records with the same product Id can be combined?Because one record has some of the data I need and the other record has different data. So essentiallythey should just be in one record together. So the output should look like this:

ProductId Name Amount Buyer Date YearsAsCustomer
1 Jones 234.44 Nichols 3/12/2011 3
2 Melon 333.00 Tripol 3/23/2011 4

How can I combine these records together? In the stored procedure the query is build in a parameter stringnamed @SQL, and then the query is executed by using the EXEC command:EXEC sp_executesql @SQL.Is their anway I can combine all of the outputted records into one record. Where the records I want to combine
have the same ProductId (As in the example I illustrated above?)

View 7 Replies


Similar Messages:

SQL Server :: How To Combine Multiple Rows Into A Comma-delimited List In Sql Server In Build Function

Jan 10, 2011

How can I combine multiple rows into a comma-delimited list in sql server in build function?? in HCL

examples :

X
---
12
15
18
20

Output : 12, 15, 18, 20

with in build function of sql server.

View 6 Replies

Forms Data Controls :: Combine Gridview Columns Under One Column And In Separate Rows

Nov 29, 2010

I have a couple of things that are not working with my Gridview:

1) I've managed to display 3 columns in one column (see code above) but the data is separated by commas, how can I display each data item in separate rows.

2) How can I make the data unique, as I have added the distinct command which I configured in my SQL data source

3) I need the rows to not display nulls, but at the moment it isn't displaying the row if one of the columns is null?

[Code]....

View 3 Replies

Access :: Combine Items From Two Table Rows Into One View Row?

May 8, 2010

Working in Access, I need to create a view which takes values from two different records in another table and puts them on one row in the view. I'm having a hard time doing this since both row items come from the same field in the original table (actually in this case, using views instead of tables).

I have two queries I try to join together, but come up with the wrong results:
vwComp1:

SELECT q.CompStatus, q.EQID, c.CompsID, q.LastName, q.FirstNameFROM _EQ AS q, Comps AS cWHERE q.CompStatus=1 AND c.CompsID=q.CompID
vwComp2:
SELECT q.CompStatus, q.EQID, c.CompsID, q.LastName, q.FirstName
FROM _EQAS q, CompsAS c
WHERE q.CompStatus=2 AND c.CompsID=q.CompID
vwAssignment:
SELECT vwComp1.*, vwComp2.*
FROM vwComp1, vwComp2

This does fine in the vwComp2 part of vwAssignment, in the sense that it displays the correct name information, etc.; but for vwComp1, it just takes the name and other fields from the first row of vwComp1 and repeats it on every row of vwAssignment. This is really strange because vwComp1 and vwComp2, when displayed individually, each correctly puts the names in each row; something like this:

Bob White Rhonda Red
Bob White Freda Freschetta
Bob White Linda Lime
Bob White Jean Green

--when it should read something like this:
Bob White Rhonda Red
Fred Redd Freda Freschetta
Jim Brown Linda Lime
Rob Black Jean Green

View 1 Replies

SQL Server :: How To Combine The Data From The Two Text Boxes And Store It In Single Column

Jul 30, 2010

I have two textboxes

1.To get the Hour

2.To get the Minutes

From user.

And in the back end... i would to Combine the data from these text boxes and store it in single column..
For eg.

If textboxHours.Text="11";
textboxMinuetes.Text="56";
In the backend it should store like..
MeetingTime (column name)
11.56

View 2 Replies

SQL Server :: Combine Two Querys Into One?

Feb 9, 2011

My query below

SELECT
WORKORDER
WORKORDER
[dbo]
WORKORDER.ACCT, MASTERFI.NAME1,
.TICKET_RECV_DT, WORKORDER.WORK_ORDER_NUM,
.LAST_ACTION,WORKORDER_DETAIL.WORKER
FROM [dbo].WORKORDER,
.MASTERFI, [dbo].WORKORDER_DETAIL.......

I want to combine two querys into one, how do i achieve this result?

View 4 Replies

SQL Server :: Combine Two Queries In One Resultset?

Sep 6, 2010

I want to combine two queries like :

select name as name1 from table1 where id = 6

and

select name as name2 from table1 where id = 2.

I need a single resultset. How can I do that?

View 26 Replies

SQL Server :: Combine Inner Joins - Get A Field Value From The First Statement

Sep 14, 2010

I have a select statement. I need to get a field value from the first statement. GOAL: Below is what I am trying to accomplish - the code below is not correct - Please modify the statement with the correct SQL Syntax. I want to query a table and based on the results I want to set the "If THE Else"statement to query then table with diffent inner joins.

SELECT * FROM CONTENTITEM CI
INNER JOIN CONTENTCATEGORY CC ON CI.CATEGORYID = CC.CATEGORYID
IF CI.FORMTYPE = 200 OR 300
SELECT * FROM CONTENTITEM CI
INNER JOIN CONTENTCATEGORY CC ON CI.CATEGORYID = CC.CATEGORYID
INNER JOIN CONTENTFORMFIELD CF ON CF.ITEMID = CI.ITEMID
WHERE CI.ITEMID = @ITEMID
ELSE
SELECT * FROM CONTENTITEM CI
INNER JOIN CONTENTCATEGORY CC ON CI.CATEGORYID = CC.CATEGORYID
WHERE CI.ITEMID = @ITEMID

View 10 Replies

SQL Server :: Can Combine Resultset Return By Union

Sep 30, 2010

Is there a way to row two and three of the result set be returned so that the

following query:

[Code]....

View 10 Replies

SQL Server :: Stroed Procedure To Combine String And Int?

Jul 20, 2010

I am wanting to produce and SQL stored procedure that will combine a the CompanyID with the CompanyName I order to display this in a drop down list/This is what i have so far....

Select CompanyID + ' - ' + CompanyName As DisplayName, CompanyID From Company

The error I get says:

"Conversion failed when converting the nvarchar value 'testcompany' to data type smallint."

Now Im presuming this is caused by the CompanyID being an int and the CompanyName being a string.

View 2 Replies

SQL Server :: Combine Two Self Referencing Queries In A Function?

Feb 23, 2011

I have a menu table which has a (mostly) unlimited number of levels/tiers:

[Code]....

I also have a working function which will give the up and down tiers based on a given MainMenuId:

[Code]....

My question is, is there a better way to do this such as combining the two querries? Every attempt I have made results in a "The Statement terminated. The maximum recursion 100 has been exhausted before statement completion"

View 4 Replies

AJAX :: Combine Libraries Into 1 Js file To Reduce Requests To Server?

Jan 27, 2011

I am using ajax control toolkits and ajax extentions in my projects. and as you know it overhead some libraries to page. How can I combine them into 1 js file to reduce requests to server ???

View 2 Replies

Combine JQuery Client And Server Side Errors In Same Summary At Top Of Page

Feb 25, 2010

I am using JQuery for all of my client side validation and Asp.net validator controls for all of my server side validation. I am using an errorlabelcontainer to store the client side validations in a summary at the top of the page, which is the requirement. All works well. My problem is, I want to display the server side asp.net errors in the same errorlabelcontainer OR display all of the client side errors in the validation summary. Either way, Both errors need to be in the same place/div. Any ideas on how to do this? I thought of maybe using the asp.net validation summary as the errorcontainer in JQuery, but I cannot find the summary. This is what I have right now.

$("#aspnetForm").validate(
{
onkeyup: false,
errorLabelContainer: $("ul", $("#FormErrors")),
wrapper: "li"
});

If you need to see more code.

View 1 Replies

SQL Server :: Combine Strings Separated By Single White Space In Column

Mar 10, 2011

i have a column in table and need to combine words seperated by single space, i am using sql server 2005.

DECLARE @text varchar(256)
SELECT @text = 'Micro Tech'

--required output MicroTech

View 3 Replies

SQL Server :: To Select Top 20 Rows But Skip The First 10 Rows?

Aug 18, 2010

I was looking for such an SQL query that it will give me the first 20 records but it will skip the first 10

There are some LIMIT and OFFSET stuff with MySQL and Postgres but what works with SQL Server?

View 2 Replies

SQL Server :: Count How Many Rows Are In Data Table

Mar 5, 2011

I have a data table called Songs It has SongId as Primary Key of type INT SongName of Type VarChar UserId of Type Int. I simply want to check how many entries are in the Table already by The UserId before they insert more. So If there are already 3 songs by that User, I want to stop the insert process and warn them they have the maxium already. I think i am halfway there already using code below but problem is that UserId is of Type GUID, and not Int so I am missing something. On my Aspx, Page, I have a DetailsView for the Database Insert. I also have the following code using BusLogic Layer and DAL

SongsBLL
public int ScalarQuery(Guid ArtistId)
{
int returnValue = ScalarQuery(ArtistId);
return returnValue;
}
Code Behind ASPX page
This in in DetailsView_ Item Inserting Event
SongsBLL number = new SongsBLL();
currentCount = Convert.ToInt32(number.ScalarQuery(currentCount).ToString());..........

View 9 Replies

Cache Combine Two User Data

Mar 15, 2011

I have a master/detail web form and i have implement a caching to hold detail data. i am facing problem that when two user login same time and enter data, cache has combined the data and both user ara getting each other data. i want every user gat his own data.

View 6 Replies

MVC :: Can Access Data.rows.length In All Browsers But In Chrome Data.rows Is Null

Feb 22, 2011

I have an Ajax call as below

[code]....

I can access data.rows.length in all browsers but In chrome data.rows is null

View 2 Replies

DataSource Controls :: Combine Data From 2 Tables

Mar 27, 2010

I have 2 tables with UserId and FirstName, LastName Columns that I want to combine the data in a Select Statement or Stored Procedure

1. The 2 tables will never have the same data, each table will be distinct

2. I want to combine first and lastnames to a full name (t1.FirstName + ' ' + t1.LastName) AS FullName

3. The statement will be used to populate a dropdownlist with UserId as Value, and Name as text

I am unsure how to accomplish this since I do not need to connect the tables, but combine the Sum of their data.

View 6 Replies

Forms Data Controls :: How To Combine Some List Items Together

Jan 8, 2011

just want to have a quick question about the value of dropdownlist listitem. I have a gridview which has its datakey value linked to a dropdownlist. In the dropdownlist I have many listitems. So I decided to combine some list items together. Originally, the values of the items are 1,2,3,4,5,6,7,8. But I want to have only 5 items by combining 5,6,7,8 into one listitem called "Others." So if the listitem "Others" is selected, the gridview will show all the records that have value 5 or 6 or 7 or 8. Is it possible? How can that be done?

I hope I made myself clear. Any question, I am happy to clarify.

View 4 Replies

Combine Data From Multiple Tables Into One View Model

Dec 5, 2010

I'm fairly new to all this, but have slowly been teaching myself C# and ASP.net MVC over the past year or so...I really tried to search for this, but haven't been able to find anything - it may be I'm using the wrong terminology!I'm using ASP.NET MVC2 with EF4 connected to a SQL Express db. Situation: Without getting into too much specifics, I have one table called 'Plan.' Under 'Plan' are several different categories that are related to a single Plan item [say Category A, Category B, Category C and Category D]. Each 'Category X' table has a beginDate, endDate and other details specific to that category.

I'd like to be able to create a summary page that combines all items from Category A, Category B, Category C, and Category D and sorts by beginDate - but only need a few of the columns [eg - begin/end date, name, id].

View 1 Replies

C# - Combine Data From Multiple Sources - Display In ASP GridView

Feb 5, 2010

I am writing a currency converting module for one of our applications. I have a list of products, a list of currencies we are interested in seeing prices for, and a list of currency rates. I want the user to be able to select which currencies from the list they see in the GridView. I also want to be able to amend my list of currencies and include a new currency, without having to make additional changes to this module. So my GridView display has to be "dynamic". Essentially I am planning on ending up with a GridView that has the following columns:

Part No - Description - USD Price - AUD Price - GBP Price

The USD price would be static as it's our base currency, the AUD and GBP are user selected and could have potentially any number of currencies listed. I would normally use a DataSet and DataTables for this work, but I am sure there is a "better" way to do it using System.Collections.Generics. Right now I have all of the data I need in List collections, but there does not seem to be a way to define how these collections relate to each other, or combine these collections into one so it can be bound to a GridView. Should I be looking at something other than List to achieve this or do I need to go back to my original approach of a DataSet and DataTables.

**UPDATE / SOME CODE**

I will explain a little bit more about what I have setup so far.

1) List of Products & Currencies - These come from an SQL DB via LINQ, so they can be any of the System.Collections.Generics objects, e.g. List, IEnumerable etc.

2) Currency Rates - These I am pulling from the European Bank public XML file. I download the file, strip the data I need out of it and currently store that as a List object.

I could store the currency rates in the database table as well, but then I have to have some sort of background process that goes and updates the rates each day. This way the rates only get updated when someone accesses the report function (which is only going to happen occasionally). So I would rather grab the latest rates "on demand". What I know I need to end up with is some object that has the following structure:

PartNo - Description - Base Price - Currency Price 1, Currency Price 2, Currency Price 3

Where the number of Currency Prices is undefined, as it's based on what currencies the user wants the report to display. It's the undefined part that I am struggling with, essentially how can I create a structured object, that I don't know the complete structure of until runtime?

View 1 Replies

Forms Data Controls :: How To Combine Two Columns In The GridView

Oct 6, 2010

If I have two two columns: Date1 and date2,I would like to display in GridView1 than one column.

Example:
Date1 = 10/06/2010
Date2 = 07.10.2010

GridView1 (date1 + date2) = 06.10.2010 - 07.10.2010

View 2 Replies

Forms Data Controls :: Using JQuery To Swap Rows In DataGrid And Postback To Server?

Mar 2, 2010

I need to swap around the rows and I do that with

[Code]....

Obviously I am using the tableDnD() function to do that, but after I swapped them, I am saving the datagrid in a DataTable as it is (altered). However this doesn't happen. I need the changes to be posted back to the server. I tried to __doPostBack() after the onDrop function with no luck.

View 1 Replies

Data Controls :: Select Number Of Rows From DropDownList And Add Rows To GridView?

May 7, 2015

I came across a situation where a user selects no of rows from dropdown , depending upon the user input, automatically that no of editable rows should appear to input data...(maximum 8 rows only)

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved