|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
SQL Query
Hello all I have a quick question with a query. I would like to use this query in Query Analyzer.
I have a table named account. Within account table there is a field named ssnum. I would like to query the account table for any record within it that has account >2 (any account that has more than 1 account) AND has ssnum with a NULL value. So essentially i would like to delete any account within the accounts table that has >1 account and has a null value in ssnum field. Can anyone help me out with that? |
|
#2
|
||||
|
||||
|
Not sure what you mean my more than one account because you list only 1 field in your table -- without something else to key on, how do you know you have a duplicate account?
__________________
Wolffy ------------------------ Teaching people to fish. |
|
#3
|
|||
|
|||
|
Ok well this is what i use currently.
select count (*), account from accounts group by account having count (*) > 1 So basically it returns all the accounts in the account table with more than 1 account. I want to delete One of those accounts the one with ssnum having a NULL Value. |
|
#4
|
||||
|
||||
|
Got it, I was missing the idea that you had an account column in the accounts table -- confuzing no?
Try something like the following: WARNING: Back up your data first -- Back up your data first -- Back up your data first (get the idea -- I'd try this on a copy of the table first) |
|
#5
|
|||
|
|||
|
I know this doesnt work but it gives you an example of what im trying to do
DELETE *, account as Expr1 From Accounts WHERE (select count (*), account from accounts group by account having count (*) > 1) and (ssnum = <NULL>) |
|
#6
|
|||
|
|||
|
Excelent i will give that a try!!!
|
|
#7
|
|||
|
|||
|
It worked! Wolffy you are God amoung Gods my friend, you just saved me hours. Appreciated.
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > SQL Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|