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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 where function delete

Author  Topic 

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-03-24 : 10:27:20
hi is there a function that i can do following

Collumn A // Collumn B

2 // null
3 // null
4 // 5
5 // null

When Collum B has a equal number in collumn A, the row that
has the match in collum A needs te be deleted

2 // null
3 // null
4 // 5

Ty

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-24 : 10:56:35
I'm not sure I'm understanding this correctly...but maybe this

delete from <urtable> where ColumnA in (select distinct ColumnB from <urtable>)
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-03-24 : 10:57:50
dang. i had a script that does this, but it keeps giving me a network interruption when i try and post it....

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-03-24 : 11:00:39
[code]
declare @foo table (A int, B int)
insert into @foo

s e l e c t 2 , n u l l
union all select 3,null
union all select 4,5
union all select 5,null

select * from @foo

delete b
from @foo a
inner join @foo b
on a.b = b.a
[/code]

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-03-24 : 11:01:06
had to space out the letters in the insert statement, or it would not post.. weird.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -