Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Doubt

Author  Topic 

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-06-05 : 03:20:44
Hi,
I have a table in my database. Now I will import the data into table from excel. Now I have Firstname,Lastname,email,phone from excel.There is a chance some email,phone can be null. Now I have to identify and update the null values with values from tables from another database which has a master table containing all values.

How to write a script?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-05 : 03:24:23
1. import from excel into table
2. update the column value from master table


update e
set col1 = m.col1
from excel_table e inner join master_table m
on e.pk = m.pk
where e.col1 is null



KH

Go to Top of Page

vmurali
Yak Posting Veteran

88 Posts

Posted - 2007-06-05 : 04:15:35
Ok thanks for update. My another database is Access db. so how to read the access db and get the values.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-05 : 04:24:04
you can use linked server.

from BOL
quote:

OLE DB Provider for Jet
The Microsoft® OLE DB Provider for Jet provides an OLE DB interface to Microsoft Access databases, and allows Microsoft SQL Server™ 2000 distributed queries to query Access databases.

To create a linked server to access an Access database

Execute sp_addlinkedserver to create the linked server, specifying Microsoft.Jet.OLEDB.4.0 as provider_name, and the full path name of the Access .mdb database file as data_source. The .mdb database file must reside on the server. data_source is evaluated on the server, not the client, and the path must be valid on the server.
For example, to create a linked server named Nwind that operates against the Access database named Nwind.mdb in the C:\Mydata directory, execute:

sp_addlinkedserver 'Nwind', 'Access 97', 'Microsoft.Jet.OLEDB.4.0',
'c:\mydata\Nwind.mdb'

To access an unsecured Access database, SQL Server logins attempting to access an Access database should have a login mapping defined to the username Admin with no password.
This example enables access for the local user Joe to the linked server named Nwind.

sp_addlinkedsrvlogin 'Nwind', false, 'Joe', 'Admin', NULL

To access a secured Access database, configure the registry (using the Registry Editor) to use the correct Workgroup Information file used by Access. Use the Registry Editor to add the full path name of the Workgroup Information file used by Access to this registry entry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\SystemDB

After the registry entry is configured, use sp_addlinkedsrvlogin to create login mappings from local logins to Access logins:

sp_addlinkedsrvlogin 'Nwind', false, 'Joe',
'AccessUser', 'AccessPwd'

Access databases do not have catalog and schema names. Therefore, tables in an Access-based linked server can be referenced in distributed queries using a four-part name of the form linked_server...table_name.

This example retrieves all rows from the Employees table in the linked server named Nwind.

SELECT *
FROM Nwind...Employees


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-09 : 07:09:00
or make use of Import/Export wizard or Opendatasource

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -