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
 General SQL Server Forums
 New to SQL Server Programming
 If statments with SQL

Author  Topic 

THM
Starting Member

4 Posts

Posted - 2011-11-14 : 01:23:32
what i want to do is take an average of some data and then preform desplay an vaule using an if statment if some conditions are true. I can get the average to work but the IF are giving me problems. Any ideas what i'm doing wrong?

SELECT SAMPLE.HOLEID,
AVG(CASE WHEN SAMPLEDETAILS.NAME = 'FRAG_DOL'AND SAMPLE.SAMPFROM BETWEEN '{ctrl::DV_FROM}' AND '{ctrl::DV_TO}' THEN cast(VALUE as FLOAT) ELSE NULL END) AS FRAG_DOL_AVG


FROM SAMPLE AS SAMPLE
LEFT JOIN SAMPLEDETAILS
ON SAMPLE.SAMPLEID=SAMPLEDETAILS.SAMPLEID
WHERE SAMPLE.PROJECTCODE = 'UG'

GROUP BY SAMPLE.HOLEID
ORDER BY SAMPLE.HOLEID


IF ( ( 'FRAG_DOL_AVG') = 0)

BEGIN
SELECT 'FRAG_DOL_AVG' as 'test'
END
ELSE
BEGIN
SELECT 'FRAG_DOL_AVG' as 'FAIL'
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-14 : 01:31:03
This is a presentation issue as its about giving display name. you dont need to do it sql. you need to add this logic to your presenatation layer using front end language to give it suitable header name.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -