sql server - Deduping contacts in SQL. Two Databases. Select statements, joins and #TempTables -
ok, 2 databases person , company.
-select contacts without caps in person.pers_firstname
-select company.comp_companycode have value of null (no assigned company code.)
i need join them on person.pers_companyid=company.comp_companyid
after have need able see results, , delete them. fields i'll need able see in results person.pers_firstname , person.pers_lastname
here's have far
select * person pers_firstname != upper(pers_firstname) collate sql_latin1_general_cp1_cs_as #temptable1 select * company comp_customernumber null #temptable2 #temptable1, temptable2 select #temptable1.pers_companyid, #temptable2.comp_companyid dbo.#temptable1 inner join dbo.#temptable2 on #temptable1.pers_companyid=#temptable2.comp_companyid
i'm getting errors @ both of commands. naturally, second block of code referencing #temptable1 , #temptable2 unable located.
select * #temptable1 person pers_firstname != upper(pers_firstname) collate sql_latin1_general_cp1_cs_as select * #temptable2 company comp_customernumber null select comp_companyid #temptable2 inner join dbo.#temptable1 on #temptable1.pers_companyid=#temptable2.comp_companyid
sql doesn't see of #temptable1 or #temptable2
correct syntax is
select * #temp table;
in case:
select * #temptable1 person pers_firstname != upper(pers_firstname) collate sql_latin1_general_cp1_cs_as select * #temptable2 company comp_customernumber null
edit: add select statement
select t1.pers_companyid, t2.comp_companyid #temptable1 t1 inner join #temptable2 t2 on t1.pers_companyid=t2.comp_companyid
edit2: how drop temp tables
you need run before
if object_id('tempdb.dbo.#temptable2 ', 'u') not null drop table #temptable2 if object_id('tempdb.dbo.#temptable1 ', 'u') not null drop table #temptable1
Comments
Post a Comment