Advertisement

05.07.2008 at 10:53AM PDT, ID: 23383663
[x]
Attachment Details

SQL Help - Uniformity

Asked by Navicerts in SQL Query Syntax, MS SQL Server, SQL Server 2005

Hello,

I am trying to query for uniformity.  I have a query that averages the weight of animals along with a counter and standard deviation.  The final column I need to add is uniformity.  I want this column to show the percentage of animals that fall within +/- 15% of the average.  As an example if there were 10 animals and the average weight was 10 pounds and 1 animal weighed 8.4 pounds and one weighed 11.6 pounds (and the other 8 weighed 10 pounds) it would be a 80% uniformity.

Thank YouStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
Declare @farmname As NVarChar(50)
Declare @recorddate As DateTime
 
Set @farmname = 'xxxxxxx'
set @recorddate = '5/1/2008'
 
 
SELECT	
	[Farm],
	[House],
	RW.[Pen Number],	
	Convert(NVarChar, [Date], 101) As [Date],
	[Sex Code],
	Convert(Decimal(6,2), Avg((Convert(Decimal(6,3), [Weight])/10))) As [Weight],
	Count(*) As Counter,
	Convert(Decimal(6,2), StDev(Weight/10)) As SD
	--Convert(Decimal(6,2), Avg((Convert(Decimal(6,3), [Weight])/10)) * .85)
	--Convert(Decimal(6,2), Avg((Convert(Decimal(6,3), [Weight])/10)) * 1.15)
FROM 
	[Prod Random Weights] As RW 
INNER JOIN 
	Location As l 
ON 
	RW.[Location ID] = l.[Location ID] 
LEFT JOIN 
	[RDA Prod Pen Master] As pm 
ON 
	l.[Location ID] = pm.[Location ID] 
AND	pm.[Pen Number] = RW.[Pen Number]
WHERE 
	[Farm] = @farmname 
AND	DatePart(dd, [Date]) = DatePart(dd, @recorddate) 
AND	DatePart(mm, [Date]) = DatePart(mm, @recorddate) 
AND	DatePart(yy, [Date]) = DatePart(yy, @recorddate) 
GROUP BY 	
	[Farm],	
	[House],		
	RW.[Pen Number],
	Convert(NVarChar, [Date], 101),	[Sex Code]
ORDER BY
 	House,
 	RW.[Pen Number],
 	[Date]
[+][-]05.07.2008 at 10:54AM PDT, ID: 21518778

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.07.2008 at 10:59AM PDT, ID: 21518821

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 11:24AM PDT, ID: 21519030

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 11:25AM PDT, ID: 21519037

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 11:43AM PDT, ID: 21519212

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 11:50AM PDT, ID: 21519274

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 12:05PM PDT, ID: 21519381

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 12:09PM PDT, ID: 21519420

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server, SQL Server 2005
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.07.2008 at 12:24PM PDT, ID: 21519548

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 12:37PM PDT, ID: 21519657

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 12:57PM PDT, ID: 21519840

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 01:00PM PDT, ID: 21519855

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 01:01PM PDT, ID: 21519861

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 01:20PM PDT, ID: 21520042

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628