SQL Server :: Return Sum Of 2 Subsets To Single SqlDataReader?

Sep 20, 2010

I still have plenty to learn about SQL... I'm pretty sure what I want to do is possible, but I'm getting lost in the syntax.

I have two tables:

TABLE A: [ID] [Name]
TABLE B: [ID] [TableA.ID] [intValue] [intTypeID]

There are 3 pieces of information I want:

Total Sum(TableB.intValue)
Sum(TableB.intValue) WHERE intTypeID = 1
Sum(TableB.intValue) WHERE intTypeID = 2

Getting one of those pieces is simple: SELECT a.ID,a.Name,SUM(b.intValue) WHERE a.ID = x GROUP BY a.ID,a.Name

I assume I need some kind of JOIN, but I can't seem to get it..

View 2 Replies


Similar Messages:

SQL Server :: Stored Procedure - Looping Into Multiple SELECT Statements To Return Single Value?

Jan 3, 2011

When can I use Stored Procedure? Is this useful for looping into multiple SELECT statements to return single value? How? Can anyone post some sample codes? I have text query and notice that my web application is slow and want to find ways to speed it up. Is there any possible ways aside from Stored Procedures?

View 4 Replies

DataSource Controls :: How To Return A Single Row Where There Is A One To Many Relationship

Jun 23, 2010

I have 2 tables. Table_A has one to many relationship with Table_B.

For example. Table_A has an ApplicantKey and in Table_B I am storing (Resume_name and CoverLetter_name for the Applicant). Joined by ApplicantKey

Now when I join them and execute the query obviously it returns me two rows. But what I want is that it should return only one row with Columns like Resume_name, CoverLetter_Name

View 2 Replies

C# - Return Linq Query Into Single Object?

Mar 16, 2011

I have this code in my controller:

public ActionResult Details(int id)
{
using (var db = new MatchGamingEntities())

[code]...

View 3 Replies

SQL Server :: DataAdapter/SQLDataReader Takes Lot Of Time For Executing A Query?

Aug 31, 2010

I have a webpage with 6 drop down lists. User can start with selecting any drop down list first, and then proceed in any order. 1. Assume when the 1st dropdown is selected first, rest 5 drop downs (except 1st) are filtered/updated based on the selected value in the 1st dropdown.2. Assume user selects the 4th dropdown second, rest 5 drop downs (except 4th) will be filtered/updated but the condition would be based on both 1st drop down and 4th drop down. But while filtering the first drop down, only the 4th drop down is used as filter (self-filter will be ignored).

The code works fine but I see a very bad performance hit in time when the user selects the fourth dropdown after selecting three drop downs. I tried using both SQLDataAdapter and SQLDataReader but neither used to solve the issue. The code takes a lot of time on one line in either of the code (which is highlighted below). When I run the query in SQLServer Mgmt Studio, the query completes in a few seconds.

[Code]....

View 5 Replies

ADO.NET :: Return A Single Row From A Database As A Strongly Typed Object?

Nov 10, 2010

I have a products table whereby I want to return a single row via a product id and use it as a data object.

I have used a .xsd dataset and a product class where I return a dataset and add the values into the product object that I created but I don't like having to write code like

"Product[0].ProductDescription" to get the product description. Is there a way of returning is straight as an object rather than a dataset?

View 2 Replies

Forms Data Controls :: Return Single Field To A Different Webpage Using Hyperlink?

Aug 6, 2010

I want to return single field to a different webpage using hyperlink.

View 12 Replies

SQL Server :: DAL Doesn't Return The Return Value Of Stored Procedure?

Nov 8, 2010

I have an update function in my data layer which is defined as:

public int UpdateRBTable(parameters ...) This calls a SQL Server Stored Procedure to perform an update function on the database.

The process does its job for updating the table. However, the stored procedure has a return value (which indicates how many rows were updated), but this return value is not returned to the application. The application always shows that a zero was returned from the stored procedure.

View 3 Replies

Web Forms :: Back Button - Action To Return Back To 2 Pages Before On Single Click?

Oct 15, 2010

[Code]....

I have created a back button on my asp page. However, I would like this back button a a sinlge click to return the user to the page 2 pages before. I have tried to enter the history.back(2) but with no luck it does not work.

View 5 Replies

Multiple Single-result Sql Server Stored Procedures Or Single Multple-result Stored Procedure?

Aug 9, 2010

Background: I use stored procedures exclusively for an ASP.NET application. I am using a DataReader to load a dataset object.

View 4 Replies

SQL Server :: Sql Server - How To Insert Text With Syntax Words And Single Quotation

Oct 17, 2010

i would like to insert text in sql server that contains words like select and a single quotation mark but sql server gives errors like if i wanna insert this :

View 1 Replies

SQL Server :: Create Password In SQL Server Single Database

Jan 20, 2011

I want to create password in single database for example when i attach My database abc.mdf or open that database then it ask me password. as like access database password..

View 3 Replies

SQL Server :: Get Return Value From Server In C# Through Data Reader?

Feb 5, 2011

I want to take my return value from sql server to c#.

my code

SQL SERVER:

ALTER procedure [dbo].[userss](@email varchar(100),@password varchar(25),@name varchar(250),@DOB varchar(20),@acc_vari int,@ip_address varchar(50),@vari_code varchar(7) )
as
begin
declare @uid int
select @uid=uid from users where email='12we'
if(@uid>0)
return 0
else
insert into users values(@email,@password,@name,@DOB,@acc_vari,@ip_address,@vari_code )
end

In this i want to take return value "return 0 " from sql server to c#.

View 3 Replies

SQLDataReader Find Value Of Each Row?

Nov 10, 2010

I used to use datasets instead of sqldatareaders and I used to be able to do something like this

If dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
lbl.Text = dataset.tables(0).Rows(0)(2).ToString())
Else
'Do Nothing
End If

This obviously doesn't work with sqldatareaders.I have code to see if the SQLDatareader has any rows but was wondering if there was a way to get the value of each rowI'm guessing this is possible and i've had a look around but can't seem to find anything

Dim conn As SqlConnection = New SqlConnection("server='h'; user id='w'; password='w'; database='w'; pooling='false'")
conn.Open()
Dim query As New SqlCommand("DECLARE @investor varchar(10), @sql varchar(1000) Select @investor = 69836 select @sql = 'SELECT * FROM OPENQUERY(db,''SELECT * FROM table WHERE investor = ''''' + @investor + ''''''')' EXEC(@sql)", conn)
Dim oDR As SqlDataReader = query.ExecuteReader()
If oDR.HasRows or dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
lbl.Text = dataset.tables(0).Rows(0)(2).ToString())
Else
'Do Nothing
End If

That is the code I have at the moment which obviously doesn't work

View 2 Replies

Using SqlDataReader In Linq?

Sep 7, 2010

In normal way of write the code as follows in DAL.

DataSet ds=db.executedataset();
IEnumerable<datarow>= ds.tables[0].asEnumerable();

For better performance can use datareader in Linq instead of DataSet

View 11 Replies

SqlDataReader To String[]?

Mar 20, 2011

why the following code doesn't work?

internal static string[] GetToolsForRole(string selectedRole) {
string[] tempStr;
ArrayList myAL = new ArrayList();

[code]...

View 2 Replies

ADO.NET :: How To Get The Number Of Rows From Sqldatareader

Mar 29, 2011

how to get the number of rows from sqldatareader

View 2 Replies

C# - Read Data From SqlDataReader?

Oct 25, 2010

I have a SQL Server 2008 database and I am working on it in the backend. I am working on asp.net/C#

SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//how do I read strings here????
}

I know that the reader has values. My SQL command is to select just 1 column from a table. The column contains strings ONLY. I want to read the strings (rows) in the reader one by one. How do I do this?

View 5 Replies

ADO.NET :: Load List From Sqldatareader?

Feb 26, 2011

How can you load a List<> object from a Datareader?I tried to do it but for some reason it is not working. Below is the code that I tried to use:

using System;
using System.Data;
using System.Configuration;

[code]...

View 1 Replies

Web Forms :: SqlDatareader Is Null?

Jul 20, 2010

This my code SHoul the sqldatareader even be null when i debug (becuase response write not working)

[Code]....

View 4 Replies

Difference Between SqlDataReader.NextResult() And MARS

Sep 19, 2010

hile i have been working with application perfomance tuning part i found an article for doing the same from Microsoft. it suggests me to reduce the round trip between application and database by using Sqlbatch statements. i got two ways to achieve it 1. SqlDataReader.NextResult() - we can use single connection to execute sql batch statements2. MARS (Multiple Active Result Sets) - we can use single connection to open multiple readers and execute the batch statements

View 2 Replies

ADO.NET :: Get Two Rows Details In Variables Using SQLdatareader?

Mar 12, 2011

i need to Get Two rows details in variables using SQLdatareader and using while loop in it.Can i do so,

my query and while loop are getting fired when i debug and see my while loop...but i dnt know how to get details and show or store it, when i will get 2 records on execution of query.

MY CODE IS BELOW...

[Code]....

View 4 Replies

C# - Cannot Read Multiple Rows From Sqldatareader

Apr 15, 2010

When I query for only one record/row, sqldatareader is giving correct result but when i query for multiple rows, its giving error on the client side. below is my code.

[code]....

View 3 Replies

DataSource Controls :: SqlDataReader Does Not Get Results

Aug 19, 2010

I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.

But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.

[Code]....

View 3 Replies

C# - Use UserControl To Display SqlDataReader Data?

May 13, 2010

i try to use userControl to display SqlDataReader data.

in the main page

public SqlDataReader Data2;
...
<uc1:WebUserControl ID="WebUserControl1" RData1="<%=Data2 %>" runat="server" />
and in the userControl
Repeater1.DataSource = RData1;
Repeater1.DataBind();........

But i keep getting this error

Cannot create an object of type 'System.Data.SqlClient.SqlDataReader' from its string representation '<%=Data2 %>' for the 'RData1' property.

View 1 Replies







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