Click here to Skip to main content
15,888,521 members
Home / Discussions / Database
   

Database

 
AnswerRe: How SQL View can be used in this scenario Pin
Krishna Aditya2-Jul-09 22:41
Krishna Aditya2-Jul-09 22:41 
AnswerRe: How SQL View can be used in this scenario Pin
David Skelly3-Jul-09 2:26
David Skelly3-Jul-09 2:26 
GeneralRe: How SQL View can be used in this scenario Pin
Krishna Aditya3-Jul-09 2:58
Krishna Aditya3-Jul-09 2:58 
GeneralRe: How SQL View can be used in this scenario Pin
David Skelly3-Jul-09 5:57
David Skelly3-Jul-09 5:57 
QuestionFull Text Search in SQL Server 2005 Pin
Isaac Gordon2-Jul-09 18:21
Isaac Gordon2-Jul-09 18:21 
AnswerRe: Full Text Search in SQL Server 2005 Pin
Niladri_Biswas2-Jul-09 18:53
Niladri_Biswas2-Jul-09 18:53 
QuestionComplicated Summation Query Help Pin
JohnQuar12-Jul-09 7:44
JohnQuar12-Jul-09 7:44 
AnswerRe: Complicated Summation Query Help Pin
David Mujica2-Jul-09 8:37
David Mujica2-Jul-09 8:37 
After thinking about this for a bit, I think I would do this by creating a TEMP table and cursor to loop through the main table.

The TEMP table would be something like this:

Category      Zero  Total    Sum
Devices          0  38111   38111
Plan         38111   6063   44147
Improvements 44174   2266    4640



Use the following code snipet to get you going with the logic ...


DECLARE  myCURSOR CURSOR FOR 
	  SELECT CATEGORY, TOTAL
	  FROM myTABLE

OPEN myCURSOR
FETCH NEXT FROM myCURSOR INTO @XCATEGORY, @XTOTAL

SET @PBAL = 0.0
	
WHILE(@@FETCH_STATUS=0)	BEGIN

  SET @GTOTAL = @PBAL + @XTOTAL

  SET @MYSQL = 'INSERT INTO #MYTEMP'
  SET @MYSQL = @MYSQL + ' VALUES(' + CHAR(39) + @XCATEGORY+ CHAR(39) + ',' + @PBAL, + ',' + @XTOTAL + ','
  SET @MYSQL = @MYSQL + @GTOTAL + ')'

  PRINT @MYSQL

  EXEC(@MYSQL)

  FETCH NEXT FROM myCURSOR INTO @XCATEGORY, @XTOTAL

END

CLOSE myCURSOR
DEALLOCATE myCURSOR

GO


Hope this helps you !Thumbs Up | :thumbsup:
GeneralRe: Complicated Summation Query Help Pin
JohnQuar12-Jul-09 8:44
JohnQuar12-Jul-09 8:44 
QuestionSequential updates Pin
Gymnast1-Jul-09 18:42
Gymnast1-Jul-09 18:42 
AnswerRe: Sequential updates [modified] Pin
Niladri_Biswas1-Jul-09 18:58
Niladri_Biswas1-Jul-09 18:58 
GeneralRe: Sequential updates Pin
Mycroft Holmes1-Jul-09 21:37
professionalMycroft Holmes1-Jul-09 21:37 
GeneralRe: Sequential updates Pin
Niladri_Biswas1-Jul-09 22:17
Niladri_Biswas1-Jul-09 22:17 
GeneralRe: Sequential updates Pin
Mycroft Holmes1-Jul-09 22:42
professionalMycroft Holmes1-Jul-09 22:42 
GeneralRe: Sequential updates Pin
Niladri_Biswas1-Jul-09 23:02
Niladri_Biswas1-Jul-09 23:02 
GeneralRe: Sequential updates Pin
Gymnast2-Jul-09 16:27
Gymnast2-Jul-09 16:27 
QuestionHelp necessary in making Query Pin
Saiyed Alam1-Jul-09 16:28
Saiyed Alam1-Jul-09 16:28 
AnswerRe: Help necessary in making Query Pin
Not Active1-Jul-09 18:02
mentorNot Active1-Jul-09 18:02 
General[Message Deleted] Pin
Niladri_Biswas1-Jul-09 18:36
Niladri_Biswas1-Jul-09 18:36 
GeneralRe: Help necessary in making Query Pin
Mycroft Holmes1-Jul-09 21:39
professionalMycroft Holmes1-Jul-09 21:39 
General[Message Deleted] Pin
Niladri_Biswas1-Jul-09 22:19
Niladri_Biswas1-Jul-09 22:19 
GeneralRe: Help necessary in making Query Pin
Mycroft Holmes1-Jul-09 22:48
professionalMycroft Holmes1-Jul-09 22:48 
AnswerRe: Help necessary in making Query Pin
Niladri_Biswas1-Jul-09 20:39
Niladri_Biswas1-Jul-09 20:39 
QuestionTrigger NOT Fireing... Pin
Elizma1-Jul-09 9:36
Elizma1-Jul-09 9:36 
AnswerRe: Trigger NOT Fireing... Pin
Blue_Boy1-Jul-09 11:22
Blue_Boy1-Jul-09 11:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.