Monday, May 07, 2012

SQL Group by


 SELECT p.PROJ_NAME ,
  max(distinct case when  (MPCF.MD_PROP_NAME)='Partner' then (LTV.LT_VALUE_TEXT)  end )PARTNER
 ,max(distinct case when   ( MPCF.MD_PROP_NAME )='Región' then  (LTV.LT_VALUE_TEXT)  end) REGION
 ,max(distinct  case when ( MPCF.MD_PROP_NAME)='Fase' then (LTV.LT_VALUE_TEXT)  end )FASE
 ,max(distinct case when ( MPCF.MD_PROP_NAME)='Area' then (LTV.LT_VALUE_FULL)  end ) AREA
 ,max(distinct case when ( MPCF.MD_PROP_NAME)='Responsable Implementación' then  (LTV.LT_VALUE_FULL)  end ) RESPONSABLE
 ,max(distinct case when ( MPCF.MD_PROP_NAME)='Responsable TISA' then  (LTV.LT_VALUE_TEXT ) end ) RESPONSABLE_IMPLE
 FROM MSP_PROJECTS P      
 INNER JOIN MSP_PROJ_CUSTOM_FIELD_VALUES PCFV ON  (P.PROJ_UID = PCFV.PROJ_UID)
 INNER JOIN MSP_CUSTOM_FIELDS MPCF ON PCFV.MD_PROP_UID=MPCF.MD_PROP_UID -- AND MPCF.MD_PROP_NAME='Partner'
 INNER JOIN MSP_LOOKUP_TABLE_VALUES LTV ON PCFV.CODE_VALUE=LTV.LT_STRUCT_UID
 where
 MPCF.MD_PROP_NAME IN('Partner','Región','Fase','Area','Responsable Implementación','Responsable TISA')
 Group by PROJ_NAME
 order by PROJ_NAME

SSAS: Visibilidad de datos a nivel de totales y o a nivel de detalle


SSAS Different Dimension Granularity

In an SSAS cube you sometimes need to connect a dimension at a different granularity than other dimensions. For example, if you have budget measures and actual numbers. If you are trying to budget your expenses you budget at a higher level than the actual amounts. You budget money for groceries, not for Eggs, Milk, and bread. But your actual amounts will be down to the individual items.

In the cube browser image below you can see this in use. Notice the budget numbers only show on the category level and not on the individual items.
SSAS Different Dimension Granularity
Here are the tables being used in this cube.
FactActuals
SSAS Different Dimension Granularity
FactBudget
SSAS Different Dimension Granularity
DimAccount
SSAS Different Dimension Granularity

To set up this you will need to open the dimension usage tab in the cube editor. Click on the connection between dim account and fact budget and set up the category code as the key between the tables. The category code will be the relationship between the dimension and the fact table. A foreign key between the tables does not need to exist.
SSAS Different Dimension Granularity
SSAS Different Dimension Granularity
One other change is to set the budget measure group to ignore unrelated dimensions. This is in the Cube Structure tab, click on the budget measure group and change this property. It will need to be false, I know this seems backwards.
 SSAS Different Dimension Granularity
That is all you need.

Wednesday, May 02, 2012

SQL - Registrar errores de carga en tabla


ALTER PROCEDURE [dbo].[spUpd_CargaDM_xxxx_FactCom-Fin]
==========*/
AS

BEGIN TRY
-- Carga Fact Finanzas y Comercial
BEGIN TRANSACTION;
EXEC usp_TW_FileNumber
EXEC usp_FactFinanzasCostos
EXEC usp_FactFinanzasFileNumber
EXEC usp_FactFinanzasMorosidad
EXEC usp_FactComercialVentas
EXEC usp_FactComercialPresupuesto
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
BEGIN
ROLLBACK TRANSACTION;
END
INSERT INTO Err.CargaDM(ErrorNumber,ErrorSeverity,ErrorState,ErrorProcedure,ErrorLine,ErrorMessage)
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
/*-----------------------------------FIN---------------------------------*/

Cargar tabla Tiempo


SET LANGUAGE spanish



SET DATEFIRST 1

declare @fi datetime, @ff datetime

set @fi = '2010-01-01'
Set @ff = '2050-31-12'

while @fi <= @ff
begin
insert into Tiempo (Idtiempo, Fecha, Anio, Mes,nummes,trimestre,semana,numdiasemana,Diasemana)
--Cuarto, Semana, NumDiaSemana, DiaSemana)
select year(@fi)*10000+month(@fi)*100+day(@fi) as TimeId,
@fi as Fecha,
year(@fi) as Anio,
--year(@fi)*100+month(@fi) as MesID,
DateName( month , DateAdd( month , month(@fi) , 0 ) - 1 )NombreMes,

convert(varchar,month(@fi))Mes,
datepart(q,@fi) as Trimestre,
datename(ww,@fi) as Semana,
datepart( dw, @fi) as NumDiaSemana,
datename( dw, @fi) as DiaSemana
set @fi = @fi + 1
end

MOSS: Ruta LOGS

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

MOSS: Ruta imagenes

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES Referencia: ~/_layouts/Images/Circle_Green.png