| Author |
Topic |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-07 : 09:16:02
|
| Hi,This query returns two rows.phonebookidfeed is nullselect phonebookidfeed, firstname, lastname from tblPhoneBookFeedNlnd group by phonebookidfeed, firstname, lastname having count(isnull(phonebookidfeed,''))>1now I would like to delete these two recordsI need something to delete these records. can you correct this query please? delete from tblPhoneBookFeedNlndselect phonebookidfeed, firstname, lastname from tblPhoneBookFeedNlnd group by phonebookidfeed, firstname, lastname having count(isnull(phonebookidfeed,''))>1 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-07 : 09:18:46
|
| [code]Delete from tblPhoneBookFeedNlnd where phonebookidfeed in (select phonebookidfeed from tblPhoneBookFeedNlnd group by phonebookidfeed, firstname, lastname having count(isnull(phonebookidfeed,''))>1[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-07 : 09:21:47
|
| will this work even if the phoneBookidfeed is null ?Thanks |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-07 : 09:24:02
|
quote: Originally posted by madhivanan
Delete from tblPhoneBookFeedNlnd where phonebookidfeed in (select phonebookidfeed from tblPhoneBookFeedNlnd group by phonebookidfeed, firstname, lastname having count(isnull(phonebookidfeed,''))>1 MadhivananFailing to plan is Planning to fail
I just tried this but it does not work. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-07 : 09:25:33
|
| Can you give some sample data?MadhivananFailing to plan is Planning to fail |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-07 : 09:42:51
|
| NULL NULL NULLNULL daniels jackNULL judge mike |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-07 : 09:55:30
|
quote: This query returns two rows.phonebookidfeed is nullselect phonebookidfeed, firstname, lastname from tblPhoneBookFeedNlndgroup by phonebookidfeed, firstname, lastnamehaving count(isnull(phonebookidfeed,''))>1
I dont think your query will return two rows for those dataCan you post actual data you used?MadhivananFailing to plan is Planning to fail |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-07 : 16:13:33
|
| I have solved the problem by using a temp table and joing it to the main table.Thanks for your time guys. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-08 : 00:54:09
|
quote: Originally posted by fmardani I have solved the problem by using a temp table and joing it to the main table.Thanks for your time guys.
WellCan you post your solution so that everyone knows it?MadhivananFailing to plan is Planning to fail |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-08 : 04:48:53
|
| --do not process the duplicates, so delete them... --this method is used since there may be no ID... select phonebookidfeed, firstname, lastname into #TEMPtblPhoneBookFeedHP from tblPhoneBookFeedHP group by phonebookidfeed, firstname, lastname having count(isnull(phonebookidfeed,'')) > 1 delete from tblphonebook where isnull(phoneBookIDfeed,'') in (select isnull(phoneBookIDfeed,'') from #TEMPtblPhoneBookFeedHP) and tblphonebook.firstname in (select firstname from #TEMPtblPhoneBookFeedHP) and tblphonebook.lastname in (select lastname from #TEMPtblPhoneBookFeedHP) and CompanyID = @CompanyID |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-08 : 05:05:31
|
WellSee if this delete query worksdelete T1 from tblphonebook T1inner join #TEMPtblPhoneBookFeedHP T2 onisnull(T1.phoneBookIDfeed,'') = isnull(T2.phoneBookIDfeed,'') and T1.firstname =T2.firstname and T1.lastname =T2.lastname where T1.CompanyID = @CompanyID MadhivananFailing to plan is Planning to fail |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2005-07-11 : 04:49:28
|
| Great.Thanks |
 |
|
|
|