Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Problem

Author  Topic 

balsoft
Starting Member

2 Posts

Posted - 2009-04-16 : 06:30:54
Hi I'm new at SQl, and i have a problem.
If I use this piece of code as a Query

SELECT SUM(ElectricityDailyUsage) as Answer
FROM ElectricalUsage

My problem is how can I save the answer as a Variable or
load the answer into a textbox.
I.ve searched the Web but are unable to find the answer
If you can please help me
Balsoft

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-16 : 06:53:04
DECLARE @ElectricityDailyUsage INT
SELECT @ElectricityDailyUsage=SUM(ElectricityDailyUsage) as Answer
FROM ElectricalUsage

Make sure @ElectricityDailyUsage has datatype same as that of ElectricityDailyUsage


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

balsoft
Starting Member

2 Posts

Posted - 2009-04-16 : 12:22:08
Hi Madhivanan, thank you for your prompt reply.
I should have said that I am accessing the database using my program in VB language
from visual studio.
Your code runs, but how do I access the variable so that I can use its value.
If you have an answer please let me know - - Thank You
Balsoft
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-16 : 13:59:17
you can make it a procedure with output parameter. then in your application use a variable to get the return value and then display it.

http://www.a1vbcode.com/vbtip-118.asp
Go to Top of Page
   

- Advertisement -