Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with a SELECT SUM() AS statement

Status
Not open for further replies.

iRead

Programmer
Mar 12, 2004
25
US
When I execute the code around these statements I get the error below. Any suggestions on why or ideas about a better way to a total from a column in a dataset with 3 or 4 filter conditions will be greatly appreciated.

Select SUM(amount) AS SQLTotal FROM T1 WHERE comID = 'C1' AND catID = 'C2' AND mnth = 'March' AND yr = '2004'

LableTotal.Text = SQLTotal;

Compiler Error Message: CS0103: The name 'SQLTotal' does not exist in the class or namespace 'ASP.rptTest_aspx'

Thank you!
iRead
 
SQLTotal is a column name not a variable.
If the query is giving only one info you can write :


LableTotal.Text = (Select SUM(amount) AS SQLTotal FROM T1 WHERE comID = 'C1' AND catID = 'C2' AND mnth = 'March' AND yr = '2004')

Maybe you'll have to convert number to text to succeed



--------------------------------------------------
[highlight]Django[/highlight] [thumbsup]
bug exterminator
tips'n tricks addict
 
Are you using this query in Microsoft's SQL Server? If so, that query will work. It looks like the problem is with the second part of the script:

LableTotal.Text = SQLTotal;

Which isn't MS SQL Server T-SQL language. Is that Visual Basic? If so, you should post this in the VB forums.

-SQLBill
 
tektipdjango and SQLBill,
Thank you each for your valuable input. The problem was with using a column like a variable in the C# code. The problem is now resolved.
iRead
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top