UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Convert Wind Direction Degrees To Text, Any Versions    
 
   
ordnance1
post Jun 17 2019, 12:43 AM
Post#1



Posts: 629
Joined: 7-May 11



I have a basic query that returns the average wind direction (in degrees) for a given day, what I would like to add is some sort of if statement(?) that will return the direction in text format.

So if WindDegrees_Avg falls between:
11.25 – 33.74999 = NNE
3375 – 56.24999 = NE
56.25 – 78.74999 = ENE
Ect..

CODE
SELECT        AVG(WindDegrees) AS WindDegrees_Avg
FROM            dbo.DataNow
WHERE        (WindSpeed <> 0)
Go to the top of the page
 
MadPiet
post Jun 17 2019, 01:14 AM
Post#2



Posts: 3,171
Joined: 27-February 09



CODE
DECLARE @Degrees DECIMAL(6,4) = 32.0;

SELECT @Degrees,
direction = CASE
    WHEN @Degrees >= 11.25 AND @Degrees <33.75 THEN 'NNE'
    WHEN @Degrees >=33.75 AND @Degrees <56.25 THEN 'NE'
    WHEN @Degrees >=56.25 AND @Degrees <78.75 THEN 'ENE'
        /* spot the missing chunk! */
    ELSE 'unk'
END
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th July 2019 - 06:30 AM