Print Page | Close Window

Inline queries

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11518
Printed Date: 30 March 2026 at 4:18am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Inline queries
Posted By: Mart
Subject: Inline queries
Date Posted: 12 August 2004 at 5:56am

Hi, I am writing a stored procedure and trying to do an inline query on the same table:

ALTER PROCEDURE djLink_sp_GetBrowserStats

AS

Declare @TotalBrowsers int

Select @TotalBrowsers = Count(*) From djLink_tblBrowsers

Select

Distinct

BrowserName,

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total,

((Select Count(*) From djLink_tblBrowsers Where BrowserName = BrowserName) / @TotalBrowsers * 100) As Percentage

From

djLink_tblBrowsers

The problem is on this line (and the line preceeding):

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total

Basically because I am doing the query in the same table it is getting confused and counting all rows, not just ones with the same browser name.

Is there anyway to get around this?

Thanks, Mart.




Replies:
Posted By: michael
Date Posted: 12 August 2004 at 9:31am


Declare @TotalBrowsers int

Select @TotalBrowsers = Count(*) From djLink_tblBrowsers

Select

BrowserName,

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total,

((Select Count(*) From djLink_tblBrowsers Where BrowserName = BrowserName) / @TotalBrowsers * 100) As Percentage

From

djLink_tblBrowsers

Group by BrowserName



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mart
Date Posted: 12 August 2004 at 10:47am
Hmm didn't seem to work, same outcome.


Posted By: Mart
Date Posted: 12 August 2004 at 11:33am

Heres a little more info:

The data in djLink_tblBrowsers:

BrowserName        & nbsp;         & nbsp;         & nbsp;         & nbsp; Platform        &nbs p;         &nbs p;         &nbs p;         &nbs p;    Javascript  Cookies     Crawler    
-------------------------------------------------- -------------------------------------------------- ----------- ----------- -----------
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
Netscape 5.0         &nb sp;         &nb sp;         &nb sp;         WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP   



Posted By: Mart
Date Posted: 12 August 2004 at 11:34am
The RTE didn't like that but you get the point


Posted By: Mart
Date Posted: 12 August 2004 at 12:03pm

I got it to work:

Declare @TotalBrowsers int
Select @TotalBrowsers = Count(BrowserName) From djLink_tblBrowsers

Select
 Distinct
 BrowserName,
 Count(BrowserName) As Total,
 Count(BrowserName) * 100 / @TotalBrowsers As Percentage
From
 djLink_tblBrowsers
Group By
 BrowserName




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net