50% OFF!!!

Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Tuesday, October 20, 2009

Excel - Copy table to one column

This article copy table to one column, i.e. convert multiple columns into one column!
(after the operation, it also allows to remove empty cells)
also allow to convert multiple columns into more than one column!

This tutorial tested and found working on:
* Microsoft Office Excel 2003 with help of: Microsoft Office Word 2003
* Microsoft Office Excel 2007 with help of: Microsoft Office Word 2007


Instructions (WORKING TUTORIAL):
1. we have an excel file that contains table with data.
2. select all table data and press COPY (Ctrl + C)
3. open new Word document (Tested on Microsoft Office Word 2003)
4. PASTE (Ctrl + V) the copied table into word document.
5. Select the table (in word document) and select MENU: Table > Convert > Table to Text
[Microsoft Office Word 2007: Data (or View, should be last one) Group > Convert to Text]
Table selection using     icon
6. Set a character that not exists in the table (for example |)
7. Keep the text selected and press on MENU: Table > Convert > Text to Table
[Microsoft Office Word 2007: Insert Group > Table > Convert Text to Table]
8. Set number of columns = 1
9. Notice that the character is still | (that we selected)
10. Press OK
11. Now we have table with 1 column (and it is selected!)
12. Select entire table and press COPY (Ctrl + C)
Table selection using     icon
13. Open new EXCEL file (or use the original file)
14. PASTE (Ctrl + V) the table.
15. NOW you have 1 Column table!!!

Hope it helped you...
:)

Thursday, June 4, 2009

Sql Server | Compare 2 tables columns


Here is a sql statement for comapring two tables (may be in diffrent DBs) columns.
This SQL statement compare only if column exist in both or not and return the difference.
You may improve the sql statement for comapring more... :)
I hope this sql script will be helpful...



DECLARE @Db1 NVARCHAR(MAX)
DECLARE @Table1 NVARCHAR(MAX)
DECLARE @Db2 NVARCHAR(MAX)
DECLARE @Table2 NVARCHAR(MAX)
DECLARE @Sql NVARCHAR(MAX)

SET @Db1 = 'MMIS_SNAP'
SET @Table1 = 'CodeTablesData'
SET @Db2 = 'MMIS_SNAP'
SET @Table2 = 'CodeTables'
SET @Sql = ' ' +
' SELECT ''in ' + @Db1 + '.' + @Table1 + ' --- not in ' + @Db2 + '.' + @Table2 + ''' AS TITLE, a.TABLE_CATALOG, a.column_name ' +
' FROM ' + @Db1 + '.INFORMATION_SCHEMA.COLUMNS a ' +
' WHERE a.column_name NOT IN (SELECT column_name ' +
' FROM ' + @Db2 + '.INFORMATION_SCHEMA.COLUMNS b ' +
' WHERE b.table_name IN (''' + @Table2 + ''')) ' +
' AND a.table_name IN (''' + @Table1 + ''') ' +

' UNION ALL ' +

' SELECT ''in ' + @Db2 + '.' + @Table2 + ' --- not in ' + @Db1 + '.' + @Table1 + ''' AS TITLE, a.TABLE_CATALOG, a.column_name ' +
' FROM ' + @Db2 + '.INFORMATION_SCHEMA.COLUMNS a ' +
' WHERE a.column_name NOT IN (SELECT column_name ' +
' FROM ' + @Db1 + '.INFORMATION_SCHEMA.COLUMNS b ' +
' WHERE b.table_name IN (''' + @Table1 + ''')) ' +
' AND a.table_name IN (''' + @Table2 + ''') ' +
''

EXEC (@Sql)




You may create store-procedure from this script, and the automaticly run it
on all your tables.
This may be automatic table columns comparison...


post your additional information as comments, thanks


ANOTHER SAMPLE, faster compare with 'Allow null' & 'Data type':



SET @Db1 = 'TestDB'
SET @Table1 = 'Users'
SET @Db2 = 'TestDB'
SET @Table2 = 'Users2'

SET @Sql = ' ' +
' SELECT ''in ' + @Db1 + '.' + @Table1 + ' --- not in ' + @Db2 + '.' + @Table2 + ''' AS TITLE, ' +
' a.TABLE_CATALOG, ' +
' a.COLUMN_NAME, ' +
' a.IS_NULLABLE, ' +
' a.DATA_TYPE ' +
' FROM ' + @Db1 + '.INFORMATION_SCHEMA.COLUMNS a ' +
' WHERE NOT EXISTS ( ' +
' SELECT b.COLUMN_NAME ' +
' FROM ' + @Db2 + '.INFORMATION_SCHEMA.COLUMNS b ' +
' WHERE b.table_name IN (''' + @Table2 + ''') ' +
' AND b.COLUMN_NAME = a.COLUMN_NAME ' +
' AND b.IS_NULLABLE = a.IS_NULLABLE ' +
' AND b.DATA_TYPE = a.DATA_TYPE ' +
' ) ' +
' AND a.table_name IN (''' + @Table1 + ''') ' +
' ' +
' UNION ALL ' +
' ' +
' SELECT ''in ' + @Db2 + '.' + @Table2 + ' --- not in ' + @Db1 + '.' + @Table1 + ''' AS TITLE, ' +
' a.TABLE_CATALOG, ' +
' a.COLUMN_NAME, ' +
' a.IS_NULLABLE, ' +
' a.DATA_TYPE ' +
' FROM ' + @Db2 + '.INFORMATION_SCHEMA.COLUMNS a ' +
' WHERE NOT EXISTS ( ' +
' SELECT b.COLUMN_NAME ' +
' FROM ' + @Db1 + '.INFORMATION_SCHEMA.COLUMNS b ' +
' WHERE b.table_name IN (''' + @Table1 + ''') ' +
' AND b.COLUMN_NAME = a.COLUMN_NAME ' +
' AND b.IS_NULLABLE = a.IS_NULLABLE ' +
' AND b.DATA_TYPE = a.DATA_TYPE ' +
' ) ' +
' AND a.table_name IN (''' + @Table2 + ''') ' +
' '

PRINT @Sql
EXEC (@Sql)



Thursday, August 21, 2008

Auto size ListView [columns]


Good feature for auto sizing the listview control.
this autosizes the columns of the list.
the auto size can be done with 2 ways:

1. adjust the width of the longest item in the column, set the Width property to -1
2. autosize to the width of the column heading, set the Width property to -2


Here is example for autosizing by the larges of the 2 options:



public static void AutoSizeListView(ListView p_listView)
{
int width1, width2;
ColumnHeader colHeader;
ListView.ColumnHeaderCollection colHeaderCollection = p_listView.Columns;

int count = colHeaderCollection.Count;
for (int i = 0; i < count; i++)
{
colHeader = colHeaderCollection[i];

// To adjust the width of the longest item in the column, set the Width property to -1
colHeader.Width = -1;
width1 = colHeader.Width;

// To autosize to the width of the column heading, set the Width property to -2
colHeader.Width = -2;
width2 = colHeader.Width;

colHeader.Width = (width1 <= width2) ? width2 : width1;
}
}