Thursday 29 December 2011

Create The Cube in SSAS

To create the cube, follow these steps and Small Example
  1. Select Microsoft SQL Server 2008 „ SQL Server Business Intelligence Development Studio from the Programs menu to launch Business Intelligence Development Studio.
  2. Select File > New > Project.
  3. In the New Project dialog box, select the Business Intelligence Projects project type.
  4. Select the Analysis Services Project template.
  5. Name the new project AdventureWorksCube2 and select a convenient location to save it.
  6. Click OK to create the new project.
  7. Right-click on the Data Sources folder in Solution Explorer and select New Data Source.
  8. Read the first page of the Data Source Wizard and click Next.
  9. Select the existing connection to the AdventureWorksDW2008 database and click Next.
  10. Select Service Account and click Next.
  11. Accept the default data source name and click Finish.
  12. Right-click on the Data Source Views folder in Solution Explorer and select New Data Source View.
  13. Read the first page of the Data Source View Wizard and click Next.
  14. Select the Adventure Works DW2008 data source and click Next.
  15. Select the FactInternetSales(dbo) table in the Available Objects list and click the > button to move it to the Included Object list.
  16. Click the Add Related Tables button to automatically add all of the tables that are directly related to the dbo.FactInternetSales table. Also add the DimGeography dimension.
  17. Click Next.
  18. Name the new view InternetSales and click Finish.
  19. Right-click on the Cubes folder in Solution Explorer and select New Cube.
  20. Read the first page of the Cube Wizard and click Next.
  21. Select the option to Use Existing Tables.
  22. Select FactInternetSales and FactInternetSalesReason tables as the Measure Group Tables and click Next.
  23. Leave all measures selected and click Next.
  24. Leave all dimensions selected and click Next.
  25. Name the new cube InternetSalesCube and click Finish.
  26. In the Solution Explorer, double click the DimCustomer dimension.
  27. Add the MaritalStaus field as an attribute, along with any other fields desired.
  28. Similarly, edit the DimSalesTerritory dimension, adding the SalesTerritoryCountry field along with any other desired fields.
  29. Also edit the DimProduct dimension, adding the EnglishProductName field along with any other desired fields.
  30. Select Project > AdventureWorksCube2 Properties and verify that your server name is correctly listed. Click OK.
  31. Select Build > Deploy AdventureWorksCube2.
  32. Right-click on the cube in Solution Explorer and select Browse.
  33. Expand the Measures node in the metadata panel.
  34. Drag the Order Quantity and Sales Amount measures and drop it on the Totals/Detail area.
  35. Expand the Dim Sales Territory node in the metadata panel.
  36. Drag the Sales Territory Country property and drop it on the Row Fields area.
  37. Expand the Dim Product node in the metadata panel.
  38. Drag the English Product Name property and drop it on the Column Fields area.
  39. Expand the Dim Customer node in the metadata panel.
  40. Drag the Marital Status property and drop it on the Filter Fields area.
  41. Click the dropdown arrow next to Marital Status. Uncheck the S checkbox.

Sample : SQL Server 2008 FOR XML - AUTO Mode

-- It is helpful to how to create the XML in auto mode
--AUTO


declare @Std table (std_id int, name varchar(10))
insert into @Std values (1,'Rajasekhar')
insert into @Std values (2,'Mihir')
insert into @Std values (3,'Hari')

declare @Sub table (sbj_id int,std_id int, sname varchar(10))
insert into @Sub values (1,3,'Reporting')
insert into @Sub values (2,3,'Scorecard')
insert into @Sub values (3,3,'Consolidation')
insert into @Sub values (4,2,'ETL')
insert into @Sub values (5,2,'Budgeting')insertinto @Sub values (6,2,'HATF')
--- Auto
select
std
.name,sub.sbj_id,sub.snamefrom @Std std,@Sub subwhere std.std_id=sub.std_idfor

select
std
xml Auto .name,sub.sbj_id,sub.snamefrom @Std std,@Sub subwhere std.std_id=sub.std_idfor xml Auto,Elements

Thursday 10 November 2011

How to find the highest salary using SQL?

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

Thursday 20 October 2011

SQL Processing order

The correct order of the Logical Query Processing Phases is as follows:
1. FROM
2. ON
3.OUTER
4.WHERE
5.GROUP BY
6.CUBE | ROLLUP
7.HAVING
8. SELECT
9. DISTINCT
10. TOP
11. ORDER BY