Jeg vil gerne regne forskellen mellem de to inner selects i procent. Problemer med følgende er at den kun returnere et helt tal, f.eks. 200 selvom det burde være 252,12.
Jeg har prøvet med CAST(xx AS float) på flere måder, men uden held.
Nogle ideer? :)
SELECT Track.TrackID, Track.TrackName,
( (CAST( ( ISNULL((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 1 AND 7), 0) - ISNULL((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 8 AND 14), 0) )
/ NULLIF((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 8 AND 14), 0)
( ( ( cast(ISNULL((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 1 AND 7), 0) as float) - cast(ISNULL((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 8 AND 14), 0) as float) )
/ cast(NULLIF((SELECT SUM(TrackStatistics.UniquePlays + TrackStatistics.UniqueDownloads) FROM TrackStatistics WHERE TrackStatistics.TrackID = Track.TrackID AND DATEDIFF(dd, @StatDate, TrackStatistics.StatisticsDate) BETWEEN 8 AND 14), 0) as float)
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.