Facebook Sign in | Join
Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.

Solution to TSQL Challenge 36 - Create a graph/Chart with TSQL By leszek_g

;with cte as
(
select
	t1.Seq
	,case when t1.Data > t2.Data then t1.Data - 1
			else t1.Data end Data	
	,case when t1.Data < t2.Data then '/' 
			when t1.Data > t2.Data then '\' 
			else '_' end s	
from TC36_Data t1
join TC36_Data t2 on t1.Seq+1=t2.Seq
)

select
	replace(t2.data,'x',' ') chart
from
(
	select
		t.N,
		cast(t.N as CHAR(1)) + '|' 
			+ (select
							case when t.N=p2.Data then p2.s
								when t.N=0 then '_'
								else 'x' end
							+ '' 
						from cte p2
						order by p2.Seq
						for xml path('')
				)
			+ case when t.N=0 then '_' else '' end data
	from (select 0 N union all select 1 union all select 2 union all select 3 union all select 4 union all select 5) t

	union all

	select
		-1,
		' 0' + left(replicate(cast('1234567890' as varchar(max)),count(1) / 10 + 1),count(1))
	from TC36_Data t
) t2      
order by t2.N desc

Performance stats of the above solution

Sr# StartTime                 Reads      Writes         CPU Duration 
--- ------------------- ----------- ----------- ----------- -------- 
  1 Dec 13 2010  3:20PM        4562         182        2590    2.790
  2 Dec 13 2010  3:46PM        4562         182        2589    2.775
  3 Dec 13 2010  4:13PM        4562         182        2652    2.769
  4 Dec 13 2010  4:39PM        4562         182        2621    2.650
  5 Dec 13 2010  5:06PM        4564         182        2574    2.746

Copyright © Rivera Informatic Private Ltd.