My excel sheets contains my table definitions as follows:
FieldName FieldType
Id Int
Name Text
Each Sheet represents a different table and I got about 20 tables with about a total of 800 fields.I need to be creating these tables in my database, in the quickest way possible. The only solutions I have in mind are:
1- Create them one by one manually
2- Copy and past the excel sheet field definitions into SQL management studio and add/adjust the necessary syntax for each field to do "Create Table" query.
I find both of these solutions time-consuming, Is there a way to directly import the table definition from an Excel Sheet?
There are a few ways to build table definitions in Excel. Either through VB script/macro and/or Excel formulas. VB Script would provide the opportunity for a more robust solution but could be more involved. However, formulas can get most of the job done quickly.
I put an example together with formulas. In your question, you present field name and field type. It would be helpful to add field width and precision for variable length string fields and numeric fields. You also mentioned that you are using SQL Server. In that case, I would use actual SQL Server field types in the spreadsheet. For example, use "VARCHAR" instead of "TEXT". The following is an example:
|A |B |C |D |E |F
--------------------------------------------------------------------------
1|FieldName |FieldType|FieldWidth|Precision| |
2| | | | |CREATE TABLE table1 ( |Typed Text
3|Id |Int | | |Id Int , |Formula
4|Name |Varchar |30 | |Name Varchar( 30 ), |Formula
5|DateOfBirth|Date | | |DateOfBirth Date , |Formula
6|HoursWorked|Numeric |5 |2 |HoursWorked Numeric( 5, 2),|Formula
7| | | | |) |Typed Text
8| | | | |go |Typed Text
Snapshot of table creation Excel worksheet
In the example, Column E rows 2 through 8 contain the resulting SQL script. Further, Column E, Row 2 is simply typed straight in as text. The same is the case for Column E Row 7 and Row 8.
For Column E Rows 3 through 6 there is a formula entered.
The formula that would be in Column E Row 3 is as follows:
=IF(ISNUMBER(D3),TRIM(CONCATENATE(A3," ",B3,"( ",C3,", ",D3,"),")),IF(ISNUMBER(C3),TRIM(CONCATENATE(A3," ",B3,"( ",C3," ",D3,"),")),TRIM(CONCATENATE(A3," ",B3," ",C3," ",D3,","))))
That formula, once pasted into Column E Row 3 could be copied down through Row 6.
The results in Column E rows 2 through 8 can then be copied and pasted into SQL Server Management Studio to create table1.
Note: Once script is in Management Studio, remove the "," in the last field definition. It's only there because the Excel formula is not robust enough to keep it from showing up.
Related
I'm having trouble hiding rows that have no data for certain dimension members for the selected measure, however there are rows for that member in the measuregroup.
Consider the following datasource for the measuregroup:
+---------+----------+----------+----------+--------+
| invoice | customer | subtotal | shipping | total |
+---------+----------+----------+----------+--------+
| 1 | a | 12.95 | 2.50 | 15.45 |
| 2 | a | 7.50 | | 7.50 |
| 3 | b | 125.00 | | 125.00 |
+---------+----------+----------+----------+--------+
When trying to create a pivottable based on a measuregroup in a SSAS-cube, this might result in the following:
However, I would like to hide the row for Customer b, since there are no results in the given pivottable. I have tried using Pivottable Options -> Display -> Show items with no data on rows but that only works for showing/hiding a Customer that's not at all referenced in the given measuregroup, say Customer c.
Is there any way to hide rows without results for the given measure, without creating a seperate measuregroup WHERE shipping IS NOT NULL?
I'm using SQL-server 2008 and Excel 2013
Edit:
For clarification, I'm using Excel to connect to the SSAS cube. The resulting pivottable (in Excel) looks like the given image.
In the DSV find the table with the shipping column and add a calculated column with expression:
Case when shipping <> 0 then shipping end
Please go to the properties window for the Shipping measure in the cube designer in BIDS and change the NullHandling property to Preserve. Change the source column to the new calculated column. Then redeploy and I am hopeful that row in your pivot will disappear.
And ensure Pivottable Options -> Display -> Show items with no data on rows is unchecked.
If that still doesn't do it connect the Object Explorer window of Management Studio to SSAS and tell us what version number it shows in the server node. Could be you aren't on the latest service pack and this is a bug.
Go in your pivot table in Excel, click on the dropdown on your customer column. In the dropdown menu you will find an option called Value Filters. There you can set something like Shipping greater than 0.1.
This filters your Customer dimension column based on the measure values.
Maybe something like this (but I don't see the pivot...)
DECLARE #tbl TABLE(invoice INT,customer VARCHAR(10),subtotal DECIMAL(8,2),shipping DECIMAL(8,2),total DECIMAL(8,2));
INSERT INTO #tbl VALUES
(1,'a',12.95,2.50,15.45)
,(2,'a',7.50,NULL,7.50)
,(3,'b',125.00,NULL,125.00);
SELECT customer, SUM(shipping) AS SumShipping
FROM #tbl
GROUP BY customer
HAVING SUM(shipping) IS NOT NULL
I just want to map dynamically lookup column in LOOKUP Transform SSIS
In my task that look up column will all ways change
For Example:
TableA
```````
Col1 | Col2 | Col3
--------+-----------+---------
1 | 2 | 3
2 | 1 | 4
3 | 2 | 1
This time lookup columns are Col1+Col2
Next day it will change to Col2+Col3
I want to map dynamic input column with ssn
Depending on how the lookup columns are defined from one day to the next, it may be easier to make the query in the Lookup transformation dynamic instead. Check out the following link:
https://suneethasdiary.wordpress.com/2011/12/28/creating-a-dynamic-query-in-lookup-transformation-in-ssis/
I'm new to designing cubes with SSAS.
In my simple cube, I have one fact table with 3 dimension tables, as below. The fact table (table1) contains a list of client IDs and other columns linking to the 3 dimensions. This all works fine.
table1
client_id | dimension_link_1 | dimension_link_2 | dimension_link_3
AAAAA | xxx |zzz |bbb
BBBBB | yyy |aaa |ccc
I have another table (table2) that contains three columns - Client ID, Classification Type and Classification Name. A client may have 1-n classifications recorded against them (i.e. ethnicity, religion, allergies etc) so the Client ID may appear on multiple rows in table2. e.g.
table2
client_id | classification_type | classification_name
AAAAA | Ethnicity | Japanese
AAAAA | Allergy | Hayfever
AAAAA | Nationality | Russian
BBBBB | Ethnicity | Spanish
BBBBB | Allergy | Aspirin
BBBBB | Nationality | Spanish
BBBBB | Physical Support | Yes
I want to add table2 into my cube so that I can aggregate the list of client IDs by the existing fact table (table1) by Classification Type and Classification Name in table2.
However, I'm not sure what the correct approach for doing this is? I tried joining table2 to the fact table (table1) as a dimension linked on Client ID but I think this only joined the two objects together using the first occurrence of the Client ID in table2.
Help! :)
Thanks,
Hologram
Import table2 as both a fact table and a dimension. Then in the cube designer in the dimension usage tab, when specifying the relationship between the measure group formed from table1 and the dimension formed from table2, choose "Many to Many" as the relationship type and ensure the "intermediate measure group" is the one you formed from table2.
I'm working on data warehouse project, and i'm stuck on moment, where i need to loop through column names in dimension table and select value coresponding to specific column name in my base data table (the one with actual data, that i want to insert into fact table). Here's my table structure:
Data Table
closing_course | max_course | min_course
234 | 241 | 187
254 | 277 | 198
Dimension Table
course_id | course_type
1 | closing_course
2 | max_course
3 | min_course
In short i want to build a procedure that FOR EVERY COURSE TYPE it will get the VALUE of each course and insert course_id and coresponding value inside FACT TABLE (among other dimension data but i think i can handle that).
I am not quite sure what you are looking for, maybe you could show an example what do you want to achieve. Here a some possible solution:
INSERT INTO FactTable (courseId,value)
SELECT 1, closing_course FROM DataTable
UNION
SELECT 2, max_course FROM DataTable
UNION
SELECT 3, min_course FROM DataTable
my problem is i can't import an excel.cvs file to my sql database, because it does not have an index key.
here is the database structure:
+-----+------+-----+-----+---------+------+-------+----+
|from | to |cont |desc |date_time| total| amount| id |
+-----+------+-----+-----+---------+------+-------+----+
id being the primary with auto increment.
content of cvs file:
12345678910 17071234569 UNITED STATES OF AMERICA California 12/15/2012 2:41 4:00 0.04536
12345678910 17861234569 UNITED STATES OF AMERICA Florida 12/15/2012 2:41 4:00 0.076
cvs in notepad ++:
12345678910,17071234569,UNITED STATES OF AMERICA,California,12/15/2012 2:41,4:00,0.04536
12345678910,17861234569,UNITED STATES OF AMERICA,Florida,12/15/2012 2:41,4:00,0.076
when i import the cvs to my database, it always says i'm missing 1 colum which is the ID,
but when i make an ID column it always says there is no data on that column, and when i input a value on the ID column in the CVS file the ID on my database gets mixed up.
ex:
+---+
|ID |
+---+
|1 |
+---+
| |
+---+
|1 |
+---+
|2 |
what can be the solution here so that i can import my cvs even if it does not have an ID column, and the files that are imported to the database will get an ID automatically.
Let me explain in simple terms. Your table need 8 arguments and you are giving it only 7. It is possible when you are inserting a record using insert statement. In case of import you must have to give all the column details. You can't leave a column even if it is auto-incremented. So you have to give the ID column your self.
Here is my suggestion: I don't know how you got the CSV file but you can very much open the CSV file in MS-Excel. Now you know how easily you can add a column there and you can generate sequence there in just multiple click.
After inserting records in your table you can know how many rows you have. Now use this command in the SQL prompt or you can always find one SQL prompt in your PHPMyAdmin:
ALTER TABLE t AUTO_INCREMENT = <number_of_rows+1>;