oracle sql

Sql code posted
created at 04 Jul 08:23, updated at 17 Jul 22:44

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
DECLARE @i INT
DECLARE @q VARCHAR(MAX)
SET @i = 1
SET @q = 'With ZoomCounts AS(
  Select count(*) as ElementCount, ''MGeoZoom' + Cast(@i  as VARCHAR) + ''' as ZoomTable, Layer, ' + Cast(@i as VARCHAR) + ' as ZoomNum from MGeoZoom' + Cast(@i as VARCHAR) + ' Group By Layer'
SET @i+=1
WHILE @i <=21
BEGIN
SET @q += '
Union ALL
'
SET @q += 'Select Count(*) as ElementCount, ''MGeoZoom' + Cast(@i  as VARCHAR) + ''' as ZoomTable, layer, ' + Cast(@i as VARCHAR) + ' as ZoomNum from MGeoZoom' + Cast(@i as VARCHAR) + ' Group By Layer'

SET @i+=1
END
SET @q += ')
Select  Layer, ZoomTable, ElementCount as Record_Count from ZoomCounts Order By Layer, ZoomNum'
EXEC(@q)
677 Bytes in 2 ms with coderay