SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question merge two SQL statement into one

    Hi I have this Store Procedure I need some help to make the Two SQL statements into one statement can anyone help

    Code:
    Create PROCEDURE GetReportByDynamicQuestion
    @DynamicQuestionID uniqueidentifier 
    AS
    BEGIN 
    	Select Distinct
    	Count (*) as [Total],
    	Response,
    	((Count (*)*100)/(select COUNT(*) 
    	from 
    	DynamicRegistration_QuestionResponse
    	where DynamicQuestionID = @DynamicQuestionID)) as [Percentage]
    
    	From
    	DynamicRegistration_QuestionResponse
    	where DynamicQuestionID = @DynamicQuestionID
    	group by Response
    
    
    	select 
    	COUNT(*) as [Total Response],
    	((Count (*)*100)/(select COUNT(*) 
    	from 
    	DynamicRegistration_QuestionResponse
    	where DynamicQuestionID = @DynamicQuestionID)) as [total Percentage]
    	from DynamicRegistration_QuestionResponse
    	where DynamicQuestionID = @DynamicQuestionID;
    END

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SELECT Response
         , COUNT(*) AS [Total]
         , 100.0 * COUNT(*) /
           ( SELECT COUNT(*) 
              FROM DynamicRegistration_QuestionResponse
             WHERE DynamicQuestionID = @DynamicQuestionID ) AS [Percentage]
         , ( SELECT COUNT(*) 
              FROM DynamicRegistration_QuestionResponse
             WHERE DynamicQuestionID = @DynamicQuestionID ) AS [total Response]
      FROM DynamicRegistration_QuestionResponse
     WHERE DynamicQuestionID = @DynamicQuestionID
    GROUP 
        BY Response
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •