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 2005 Forums
 Transact-SQL (2005)
 help with query (average length of column)

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2007-08-03 : 08:50:09

Hi,

I have a table as shown with the CREATE table statement below.

I am looking to find a way to run a query that shows on average what how full each row is according to its "response" column, and I want to break that down by questionID. It would be ok to hardcode the value of "750" as the maximum (100% full column)

How would I go about doing this ? A desired resultset would be formatted like this below.


Thanks very much for any assistance!!
mike123

questionID,averageFillPercentage,averageCharacters

1, 50% ,375
2, 23% ,172.5
3, 90% ,675
4, 11% ,82.5
5, 65% ,487.5





















CREATE TABLE [dbo].[tblQuestions](
[userID] [int] NOT NULL,
[questionID] [tinyint] NOT NULL,
[response] [varchar](750) NULL
)

GO


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-03 : 08:59:57
select questionid,cast(response as float)/750.0*100 as averageFillPercentage,response as averageCharacters from tblQuestions


Madhivanan

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

- Advertisement -