selected table Record insert into another table

Posted by Sagarp under Sql Server on 11/26/2009 | Views : 3307 | Status : [Member] | Replies : 2
HI



i have fire this SQL query against to LDAP;
SELECT *
FROM OPENQUERY (ADSI,
'SELECT co, whenCreated, whenChanged, sAMAccountName,objectGUID,sn, givenName, displayName, mail, telephoneNumber, mobile,
physicalDeliveryOfficeName, facsimileTelephoneNumber, title, department, company, manager, ipPhone, userAccountControl, badPwdCount
from ''LDAP://DC=domain,DC=com'' WHERE objectClass=''User''')

i got all this record but i have insert all this colun value in another table how can i do?


Thanks
sagarp

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/



Responses

Posted by: Vuyiswamb on: 11/27/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Sagarp

if you have a This Query

SELECT *
FROM OPENQUERY (ADSI,
'SELECT co, whenCreated, whenChanged, sAMAccountName,objectGUID,sn, givenName, displayName, mail, telephoneNumber, mobile,
physicalDeliveryOfficeName, facsimileTelephoneNumber, title, department, company, manager, ipPhone, userAccountControl, badPwdCount
from ''LDAP://DC=domain,DC=com'' WHERE objectClass=''User''')


and insert in a Table that is defined like this

select Col1,Col2,Col3,Col4

from anotherTable


then your above Query should be written as


insert into AnotherTable
SELECT Col1,Col2,Col3,Col4
FROM OPENQUERY (ADSI,
'SELECT co, whenCreated, whenChanged, sAMAccountName,objectGUID,sn, givenName, displayName, mail, telephoneNumber, mobile,
physicalDeliveryOfficeName, facsimileTelephoneNumber, title, department, company, manager, ipPhone, userAccountControl, badPwdCount
from ''LDAP://DC=domain,DC=com'' WHERE objectClass=''User''')


Thank you for posting at Dotnetfunda

Vuyiswa Maseko



Thank you for posting at Dotnetfunda
[Administrator]

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sqllike on: 12/1/2009 [Member] Starter

Up
0
Down
Simple, in your query
"SELECT *  FROM OPENQUERY (ADSI, "


Modify it into
"SELECT * INTO NEW_TABLE_NAME FROM OPENQUERY (ADSI,"


You will get a table, from next time, you can use that table which is already created

Insert into   NEW_TABLE_NAME

Your select query.


Regards,
Sriram


Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response