SQL Syntax for Delete Entire Rows Mgmt Studio

Delete from Skus Where Sku > '" & Sku.ToString(399999) & "'

Open in new window


I need to delete only those records that are numbered 399999 and up. Looks like the field isn't an integer, so I can't get it to work right. I found the line above online, but it deletes ALL the records.

If it's easier, I can just delete all BUT the records where SKU <= 2000

I'll be trying to find an online solution while I wait.

Thanks in advance!!
LVL 22
Anne TroyEast Coast ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>delete only those records that are numbered 399999 and up
>Looks like the field isn't an integer
You'll need to convert the char value into a number in order to use >.
DELETE FROM Skus 
WHERE CAST(Sku as numeric(19,4))  > 399999
   AND ISNUMERIC(Sku) = 1

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anne TroyEast Coast ManagerAuthor Commented:
Hmmm... Seemed to work for a bit, then...

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.

Now, I'm checking what it DID delete.
0
Anne TroyEast Coast ManagerAuthor Commented:
Okay. It didn't delete any. Still looking.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Daniel WilsonCommented:
You have something non-numeric in that field causing the CAST to fail.  I would take a look at those with non-numeric Sku's first:

SELECT * from Skus where isNumeric(Sku) = 0

Assuming that you can safely delete them:

DELETE from Skus where isNumeric(Sku) = 0

Then run Jim's query.
0
Anne TroyEast Coast ManagerAuthor Commented:
Thanks, guys. I've had to pass this on, but I appreciate your help!
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the split.  Good luck with your project.  -Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.