RE: CROSS TAB query -
01-26-2004
, 11:31 AM
Hi venkata
See if this might give you an idea
REATE PROCEDURE [DBO].[CRIA CUBO] A
Set NoCount O
declare @t_NAME char(50
declare @Csql char(250
DECLARE TIPO_CHAMADA CURSOR FO
Select Distinct RTRIM([Tipo de Chamada]
From TMP_CUBE_ORIGINAL
OPEN TIPO_CHAMAD
DROP TABLE TMP_CUB
SELECT Site,Tipo_Linha,[Nr Origem],[Grand Total] INTO TMP_CUBE FROM TMP_CUBE_ORIGINAL WHERE [Tipo de Chamada] IS NUL
FETCH NEXT FROM TIPO_CHAMADA into @t_nam
WHILE @@FETCH_STATUS =
BEGI
SELECT @Csql = ' ALTER TABLE TMP_CUBE ADD [' + RTRIM(@t_name) +'] [MONEY] NULL
execute(@Csql
FETCH NEXT FROM TIPO_CHAMADA into @t_nam
EN
CLOSE TIPO_CHAMAD
OPEN TIPO_CHAMAD
FETCH NEXT FROM TIPO_CHAMADA into @t_nam
WHILE @@FETCH_STATUS =
BEGI
SELECT @Csql = 'UPDATE TMP_CUBE SET [' + RTRIM(@t_name) +'] = B.[Grand Total] FROM TMP_CUBE A,TMP_CUBE_ORIGINAL B WHERE A.SITE=B.SITE AND A.TIPO_LINHA=B.TIPO_LINHA AND A.[Nr Origem]=B.[Nr Origem] and B.[Tipo de Chamada]='''+ RTRIM(@t_name) +'''
Execute(@Csql
FETCH NEXT FROM TIPO_CHAMADA into @t_nam
EN
DEALLOCATE TIPO_CHAMAD
G
----- Venkata wrote: ----
Hello SQL Gurus
There are 3 tables x ,Y AND XY
i.e.
X is one Dimenstion table
Y is another Dimension tabl
By Joining the Row and the Column dimension
table we get the cell which we need to check
in the XY table whether that data exists or no
If it exists then display the descriptio
otherwise leave it blan
X table contains 5 records
x
x
x
x
x
Y table contains 4 record
y
y
y
y
XY table may contain
x1y
x2y
x4y
I need to get the Output as follow
y1 y2 y3 y4
x1 x1y1 NULL NULL NUL
x2 NULL NULL x2y3 NUL
x3 NULL NULL NULL NUL
x4 NULL NULL NULL x4y
x5 NULL NULL NULL NUL
I am not expecting the complete solution
atleast some idea how to go through it
so that I can go forward
Thanks in Advanc
Have a Nice tim
Regard
Venkat |