Monday, February 3, 2014

SQL Server: Import Tab From Excel

--FOR XLS FILES (ALL COLUMNS EXAMPLE)

SELECT * INTO NEW_TABLE_NAME
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;Database=FILESOURCE&NAME.xls', 'SELECT * FROM [TABNAME$]')


--FOR XLSX FILES (SPECIFIC COLUMNS EXAMPLE)

SELECT
[COLUMN_NAME],
[ANOTHER_COLUMN_NAME]
INTO NEW_TABLE_NAME
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=FILESOURCE&NAME.xlsx', 'SELECT * FROM [TABNAME$]')


--LIVE EXAMPLE FOR FY11 ES, XLSX FILE

SELECT
[Legacy Sales Order Identifier],
LEFT([Legacy Sales Order Identifier],9) AS [ES Transaction Number],
'Int ES' AS [Sales Channel Name],
[Sales Motion]
INTO ESTS_Data
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=C:\location\filename.xlsx', 'SELECT * FROM [FY11 ES Data 4-14-11$]')

Read More

SQL Server: Enable 'Ad Hoc Distributed queries'

If you want to use OpenDataSource or OpenRowSet query, then you must have to enable “Ad Hoc Distributed queries”. It is disabled by default as a part of security configuration as per Microsoft.
You can set this option by two ways.
1.)    sp_configure command
2.)    Surface area configuration.
Since I am a script bee, I will explain steps for sp_configure.
You can run sp_configure to see current status of “run_value” field. If you don’t able to see “Ad Hoc Distributed queries” in the results set.  You have to enable “Show advanced option” by following command.
sp_configure 'show advanced options', 1
Reconfigure
GO
You may get message
Configuration option ‘show advanced options’ changed from 0 to 1. Run the RECONFIGURE statement to install.

Once you are done with that, you can see “Ad Hoc Distributed queries” in list of sp_configure. You have to set “Run_value” to “1”. If it is “0” than run following command.

sp_configure 'Ad Hoc Distributed Queries', 1
Reconfigure
GO
Which will show you following message.
Configuration option ‘Ad Hoc Distributed Queries’ changed from 0 to 1. Run the RECONFIGURE statement to install.
Once you will go through the procedure described here, you will be able to run OpenRowSet and OpenDataSource query.


Read More

SQL, Excel, MS Access: First Word in String

Some examples, find out yourself, hope this helps

IN SQL

--Taking the first word of the Partner Name (FIELD) in this case
(CASE WHEN CHARINDEX(' ',[FIELD]) = 0 THEN UPPER([FIELD])
 ELSE REPLACE(UPPER(SUBSTRING(LTRIM([FIELD]),1,CHARINDEX(' ',[FIELD]))),',','')
 END)



IN EXCEL
=IF(ISERROR(LEFT(B2,FIND(" ",B2)-1)),B2,LEFT(B2,FIND(" ",B2)-1))


IN ACCESS
TRIM(Left([Yourfieldname], InStr([Yourfieldname], " ")))



Read More

What is the mathematical formula to calculate growth % ?

To increase Sale Growth

The amount of increase is the new value after growth less the original amount before the growth. The percent growth is the amount of increase times 100% divided by the original amount.

As an example, let's say the number of students in a school grows from 800 one year to 896 the next. First, subtract:
896 - 800 = 96. This is the increase. Next, divide by the original amount:
96(100%) / 800 = 12%. This is the percent increase.


SQL Server 2008 R2: Configure Server Startup Options (SQL Server Configuration Manager)

SQL Server 2008 R2

Use SQL Server Configuration Manager to configure startup options to be used each time the Database Engine starts. For a list of startup options, see Using the SQL Server Service Startup Options.
SQL Server Configuration Manager writes startup parameters to the registry. They take effect upon the next startup of the Database Engine.

Note
On a cluster, changes must be made on the active server while SQL Server is online, and will take effect when the Database Engine is restarted. The registry update of the startup options on the other node will occur upon the next failover.

To configure startup options
  1. In SQL Server Configuration Manager, click SQL Server Services.
  2. In the right pane, right-click SQL Server (<instance_name>), and then click Properties.
  3. On the Advanced tab, in the Startup Parameters box, type the parameters separated by semicolons (;).
    For example, to start in single-user mode, insert
     -m; in front of the existing startup options, and then restart the database. (When you start SQL Server in single-user mode, first stop SQL Server Agent. Otherwise, SQL Server Agent might connect first and prevent you from connecting as a second user.)

Important
After you are finished using single-user mode, you must remove the -m; from the Startup Parameters box before you can restart the server instance in the normal multi-user mode.
  1. Click OK.
  2. Restart the Database Engine.



Read More

SQL Server 2008 R2: Restore the master Database (Transact-SQL)

SQL Server 2008 R2

This topic explains how to restore the master database from a full database backup.
To restore the master database
  1. Start the server instance in single-user mode.
    For information about how to specify the single-user startup parameter (
    -m), see How to: Configure Server Startup Options (SQL Server Configuration Manager).
  2. To restore a full database backup of master, use the following RESTORE DATABASE Transact-SQL statement:
    RESTORE DATABASE master FROM
     <backup_device> WITH REPLACE
    The REPLACE option instructs SQL Server to restore the specified database even when a database of the same name already exists. The existing database, if any, is deleted. In single-user mode, we recommend that you enter the RESTORE DATABASE statement in the sqlcmd utility. For more information, see Using the sqlcmd Utility.

Important
After master is restored, the instance of SQL Server shuts down and terminates the sqlcmd process. Before you restart the server instance, remove the single-user startup parameter. For more information, see How to: Configure Server Startup Options (SQL Server Configuration Manager).
  1. Restart the server instance and continue other recovery steps such as restoring other databases, attaching databases, and correcting user mismatches.

The following example restores the master database on the default server instance. The example assumes that the server instance is already running in single-user mode. The example starts sqlcmd and executes a RESTORE DATABASE statement that restores a full database backup of master from a disk device:Z:\SQLServerBackups\master.bak.
 Note
For a named instance, the sqlcmd command must specify the -S<ComputerName>\<InstanceName> option.
C:\> sqlcmd
1> RESTORE DATABASE master FROM DISK = 'Z:\SQLServerBackups\master.bak' WITH REPLACE;
2> GO



Read More

SQL Server Management Studio: Set a Database to Single-user Mode

This topic describes how to set a user-defined database to single-user mode by using Object Explorer in SQL Server Management Studio. Single-user mode specifies that only one user at a time can access the database and is generally used for maintenance actions.

Caution
If other users are connected to the database at the time that you set the database to single-user mode, their connections to the database will be closed without warning.
The database remains in single-user mode even if the user that set the option logs off. At that point, a different user, but only one, can connect to the database.

To set a database to single-user mode
  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
  2. Right-click the database to change, and then click Properties.
  3. In the Database Properties dialog box, click the Options page.
  4. From the Restrict Access option, select Single.
  5. If other users are connected to the database, an Open Connections message will appear. To change the property and close all other connections, click Yes.




Read More

Excel: Case changing and checking

A co-worker of mine came to me with a problem. Say you have a column with mixed upper and lower text, and wanted to switch everything to upper case. The slow way would be to add a helper column, painstakingly insert individual UPPER formulas next to each lower case cell, then individually paste values back into the original column.

Or just use the following formula (and method).

It checks if the cell is already upper case and simply reprints it in the helper column, otherwise it applies the Upper function to the cell. Then, all you have to do is paste in the values and then copy the entire block of data over the original column (or delete the original column, if applicable), without worrying about which cells need to be copied and pasted. Much faster and easier than the "hunt and peck" method.

=IF(EXACT(A1,UPPER(A1)),A1,UPPER(A1))

This can work with lower and proper case as well, just substitute the words "LOWER" or "PROPER" as appropriate in the above formula. You could even just use =UPPER(A1).

Case checking
In Case Changing in Excel I presented a VBA based method for changing text case inside cells on a worksheet. Here are some formulas that may be used to check if a cell is a certain case.

Is proper case? (Exact method)
=EXACT(A1,PROPER(A1))
Is upper case? (Exact method)
=EXACT(A1,UPPER(A1))
Is Lower case? (Exact method)
=EXACT(A1,LOWER(A1))
And if needed, we can also check if specific parts of a text entry are upper or lower case, using the CODE function. These two examples check if the first letter of a cell is upper or lower case.

Is upper case? (Code method)
=AND(CODE(LEFT(A1,1))>=65,CODE(LEFT(A1,1))<=90)
Is lower case? (Code method)
=AND(CODE(LEFT(A1,1))>=97,CODE(LEFT(A1,1))<=122)
We could also use the Exact function, i.e. =EXACT(LEFT(A1,1),UPPER(LEFT(A1,1))).

If you want to learn the code values for each letter of the alphabet as shown above, just enter =CHAR(ROW()) in cell A1 and fill down. Rows 65 through 90 are the capital letters; rows 97 through 122 are the lowercase letters.



Read More

McAffee: remove host intrusion prevention

How to manually remove Host Intrusion Prevention Agent 7.0

Environment
For details of all supported operating systems, see KB51109.
Solution
CAUTION: This article contains information about opening or modifying the registry.
  • The following information is intended for System Administrators. Registry modifications are irreversible and could cause system failure if done incorrectly.
  • Before proceeding, McAfee strongly recommends backing up your registry and understanding the restore process. For more information, see: http://support.microsoft.com/kb/256986.
  • Do not run a .REG file that is not confirmed to be a genuine registry import file.

IMPORTANT: This article recommends that you use the Microsoft Windows Installer Cleanup Utility (MSICUU2.exe), which is designed to help resolve uninstall problems in applications that use the Windows Installer technology.

Effective June 25, 2010, Microsoft retired MSICUU2.exe because of conflicts with Microsoft Office 2007. MSICUU2.exe is no longer available from the Microsoft website.

This article retains procedures involving MSICUU2.exe in case you have an existing copy of MSICUU2.exe. However, before you use it, review the advice given on the Microsoft website at: http://support.microsoft.com/kb/290301.

To completely remove the Host Intrusion Prevention agent

Step 1 - Disable the Host Intrusion Prevention agent
NOTE: Disable the Host Intrusion Prevention module from the Host Intrusion Prevention client UI before proceeding with the steps below.
  1. Click Start, Run, type cmd and click OK.
  2. At the command prompt, type each of the commands below and press ENTER after each:

    net stop hips
    net stop enterceptagent
    net stop firepm
  3. Close the Host Intrusion Prevention client interface.
  4. Press CTRL+ALT+DEL, and in the Security menu click Task Manager.
  5. Select firetray.exe and click End Process.
     
Step 2 - Unload the ePolicy Orchestrator (ePO) Plugin
  1. Click Start, Run, type regedit and click OK. 
  2. Delete the following registry key:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\ePolicy Orchestrator\Application Plugins\HOSTIPS_7000]
     
  3. Click Start, Run, type cmd and click OK.
  4. Type the following command and press ENTER:

    regsvr32 -u fireepo.dll
Step 3 - Remove Talkback
  1. Click Start, Run, type cmd and click OK.
  2. Type the following command and press ENTER:

    C:\Program Files\Common Files\McAfee Inc\TalkBack\tbmon.exe -delref
  3. Click Start, Run, type explorer and click OK.
  4. Delete the folder: C:\Program Files\Common Files\McAfee Inc\TalkBack
  5. Click Start, Run, type regedit and click OK.
  6. Locate and expand the following registry key:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls]
  7. Under SharedDlls, delete the each of the following keys:

    C:\Program Files\Common Files\McAfee Inc.\TalkBack\dbghelp.dll
    C:\Program Files\Common Files\McAfee Inc.\TalkBack\TBMon.exe
    C:\Program Files\Common Files\McAfee Inc.\TalkBack\TBMon.loc
    C:\Program Files\Common Files\McAfee Inc\TalkBack\TBMon.exe
Step 4 - Remove the firehk driver
  1. Click Start, Run, type cmd and click OK.
  2. Type the following command and press ENTER:

    C:\Program Files\McAfee\Host Intrusion Prevention\Inf\installfirehk.bat /u
  3. Click Start, Run, type regedit and click OK.
  4. Delete the following registry keys:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Firehk]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FirehkMP]
  5. Navigate to: C:\windows\system32\drivers\.
  6. Delete the file firehk.sys.
     
Step 5 - Delete the HIPSCore service and remove the drivers
  1. Click Start, Run, type regedit, and click OK.
  2. Delete the following registry key:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\hips]
  3. Click Start, Run, type cmd and click OK.
  4. Type the following command and press ENTER:

    C:\Program Files\McAfee\Host Intrusion Prevention\HIPSCore\mfehidin.exe -u HIPK.sys HIPPSK.sys HIPQK.sys
  5. In the registry editor, delete each of the following registry keys:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HIPK]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HIPPSK]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HIPQK]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mfehidk]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mfetdik] 
      (see below)

    IMPORTANT: If VirusScan Enterprise 8.x is installed on the computer, do not remove the mfetdik key. This disables the VirusScan Enterprise On-Access Scanner if Host Intrusion Prevention is not reinstalled.

     
  6. Delete each of the following files:

    C:\windows\system32\drivers\HIPK.sys
    C:\windows\system32\drivers\HIPPSK.sys
    C:\windows\system32\drivers\HIPQK.sys
    C:\windows\system32\hipqa.dll
    C:\windows\system32\hipis.dll
    C:\windows\system32\mfehida.dll 
  7. From the command prompt, type the following command and press ENTER:

    C:\Program Files\McAfee\Host Intrusion Prevention\HIPSCore\HIPSCoreReg.exe -u
  8. In the registry editor, delete the following key:

    [HKEY_LOCAL_MACHINE\SOFTWARE\McAfee\HIPSCore]
Step 6 - Delete services and drivers
  1. Click Start, Run, type regedit and click OK.
  2. Delete each of the following keys:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\enterceptAgent]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FirePM]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\firelm01]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FireTDI]
  3. Click Start, Run, type explorer and click OK.
  4. Delete each of the the following files:

    C:\WINDOWS\system32\drivers\firelm01.sys
    C:\WINDOWS\system32\drivers\FirePM.sys
    C:\WINDOWS\system32\drivers\FireTDI.sys
Step 7 - Remove the remaining Host Intrusion Prevention registry entries
  1. Click Start, Run, type regedit and click OK.
  2. Delete each of the following keys:

    [HKEY_LOCAL_MACHINE\SOFTWARE\McAfee\HIP]
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\enterceptAgent]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Entercept\EnterceptAgent]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\McAfee Fire]
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\
    McAfee Host Intrusion Prevention Tray]
Step 8 - Remove Host Intrusion Prevention files
  1. Click Start, Run, type explorer and click OK.
  2. Delete the folder: C:\Program Files\McAfee\Host Intrusion Prevention.
  3. Delete each of the following files:

    C:\WINDOWS\system32\FireCL.dll
    C:\WINDOWS\system32\FireCNL.dll
    C:\WINDOWS\system32\FireComm.dll
    C:\WINDOWS\system32\FireCore.dll
    C:\WINDOWS\system32\FireEpo.dll
    C:\WINDOWS\system32\FireNHC.dll
    C:\WINDOWS\system32\FireSCV.dll 
Step 9 - Remove the Host Intrusion Prevention Start Menu shortcut
  1. Click Start, Run, type explorer and click OK.
  2. Navigate to: C:\Documents and Settings\All Users\Start Menu\Programs\McAfee\.
  3. Delete the Host Intrusion Prevention shortcut.
     
Step 10 - Additional clean up
Use the Microsoft MSIZap (MSIZAP.exe) or the Microsoft Windows Installer Cleanup utility (MSICUU2.exe) to remove the MSI registry values of the Host Intrusion Prevention product.  
For information about the Microsoft MSIZap or the Windows Installer Cleanup utility, see: http://msdn.microsoft.com/en-us/library/aa370523(VS.85).aspx


Steps using Microsoft MSIZAP:
  1. Click Start, Run, type cmd, and click OK
  2. Type the following command and press ENTER:

    msizap.exe TW! {B332732A-4958-41DD-B439-DDA2D32753C5}
  3. Restart your client.
Steps using the Windows Installer Cleanup Utility:
See KB53373 for important information regarding downloading the Windows Installer Cleanup utility. For additional information, see: http://support.microsoft.com/kb/290301/en-us.

NOTE: The Microsoft Windows Installer Cleanup utility is still available at your own risk from:  http://download.microsoft.com/download/e/9/d/e9d80355-7ab4-45b8-80e8-983a48d5e1bd/msicuu2.exe
  1. Click Start, All Programs, and run Windows Install Clean Up.
  2. Select the McAfee Host Intrusion Prevention product.
  3. Click Remove.
  4. Restart your client.
     
Related Information
KB58832 - How to manually remove Host Intrusion Prevention 6.x



Read More

SQL Server: Import MS Access DB Tables into SQL Server

Microsoft SQL Server 2005 and 2008 offer the Import and Export Wizard to move data to and from an external source. You can also create a basic SQL Server Integration Services (SSIS) package which can be used later in the Business Intelligence Development Project.
With the Import and Export wizard, you can access different types of data sources. These sources include database formats such as Microsoft Access, Microsoft SQL Server, flat files, Microsoft Excel, and Oracle. This article discusses importing Access 2007 database tables into MS SQL Server 2005/2008.

Importing Microsoft Access MDB databases (2003-format or earlier) is a built in feature of SQL Server. However, because of the difference between the database engine of Microsoft Access 2007 and earlier versions, it is not possible to connect to the Access 2007 database (*.ACCDB) using the built-in data source “Microsoft Access”. To import data from a Microsoft Access 2007 database, you must install the OLEDB Provider for Microsoft Office 12.0 Access Database Engine. Refer to the following FMS tip for details:

After installing this driver, open SQL Server Management Studio and connect to the desired instance of SQL Server database engine. In the Object Explorer, it shows database list available in that instance of SQL Server. Select a desired database or create a new one. Right Click this database and select Tasks -> Import Data.


Now follow the several pages of the wizard. The steps below detail how to import data into a SQL Server 2005 database, but the steps are very similar in SQL Server 2008.
On the first page, select the Data source from which you want to import the data. There are several data sources also available such as:
  • Microsoft OLEDB provider for SQL Server
  • Microsoft OLEDB provider for Oracle
  • SQL Native Client
  • Microsoft Access
  • Microsoft Excel, etc…
Because of the difference between the database engine of Microsoft Access 2007 and earlier version of Microsoft Access, it is not possible to connect to the Access 2007 database using data source “Microsoft Access”. You can use this if you wish to import data from a MDB format, but not an ACCDB from Access 2007.
If you have properly installed the 2007 Office System driver, you will see another Data Source option: “Microsoft Office 12.0 Access Database Engine.”

Select this option to import from an ACCDB file. Then click the Properties button to open the Data Link Properties window:

On the Data Link Properties page, provide the location of database in to the Data Source field, and enter the User name and password if applicable. Click on the Test Connection and make sure it succeeds.
Click OK to close the Data Link Properties sheet, and continue to the next page of the Wizard, to choose the Destination.

Your destination is SQL Native Client, since you want to import to SQL Server. The server name and database should already contain the database that you want to import to.
Click Next to continue, and choose option for Copy data from one or more tables or views.

Click Next, and select the Source Tables or Views to import. If necessary use the Edit Mapping button to map the Columns correctly.

The next screen of the wizard shows two options. First one is to Execute Package Immediately and second one is to save SSIS package which can be used in the Business Intelligence Development Studio Project.

Click Next and Finish the Wizard. It shows all successful action list and errors if any.

Once execution is finished, you can click on the database and see the imported tables from Access database.

This way you can import data from Access 2007 database tables and also create an SSIS package for a Business Intelligence Development Project.
The limitation of the wizard is it doesn’t share sources with other packages and more advanced logic can’t be applied in the wizard.



Read More

MS Access: Merge Tables

Instructions:

        1        Open Access 2007/2010 and open the database that contains the tables to be merged. Go to the "Create" tab and click "Query Design."
        2        Double-click the table that you want to merge. This will be your source table. After the selection has been made, click the "Close" button. The selected table will appear in the top half of the query designer.
        3        Double-click the asterisk that appears at the top of the table list of fields to select all of the table's fields and move them to the query design grid (bottom half of the query designer).
        4        Click the "Home" tab and then click "Design View." Click the "Append" button on the "Design" tab. You'll be asked if you want to append the data to the current database or a different one. Import the data to the current database by clicking "Current Database." From the "Table Name" box, select the target table. Click "OK."
        5        Move your mouse pointer to the top of the Access window and click the "Run" button (look for the red exclamation mark). You'll receive a message that you're about to append "x" number of rows to the target table you selected in the previous step. Click "Yes" to run the query and append the data.




Read More

Read more: How to Merge Tables in Access 2007 | eHow.com http://www.ehow.com/how_7328212_merge-tables-access-2007.html#ixzz1JWv2Ng8L

Excel: Remove characters after a space

Quickly... here's an example of what you're looking for

 I have this string in cell B2
1000FRA150-G54 90D 12'


with this version of the formula, I'm returning the the text before the blank space
=LEFT(B2,FIND(" ",B2,1)-1)
Result: 1000FRA150-G54

with this version of the formula, I'm returning the text after the blank space
=RIGHT(B2,(LEN(B2)-FIND(" ",B2,1)))
Result: 90D 12'


Read More