Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PROC SQL: Delete rows in which two date fields differ by more than 250 days

Posted on 2009-05-18
6
Medium Priority
?
770 Views
Last Modified: 2012-05-07
Hi all, I;m not familiar with PROC SQL (I think its similar to MS SQL)

I am running a statistics program called SAS and am trying to delete certain rows in a database. The fields 'Date_Announced' and 'Date' are the ones I am concerned with. I'm trying to subtract the two coloumns and then delete the rows for which the result is >250 . The sheet is called Asx.mergernew.

Can someone help me with the exact command to type into my command window?
0
Comment
Question by:hubfub
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409778
you can do something like:

delete from YourTableName where DATEDIFF(dd,Date_Announced,[date])>=205
0
 
LVL 31

Accepted Solution

by:
RiteshShah earned 1500 total points
ID: 24409789
if you want in stored procedure than use this one.




create proc DeleteRecord
as
begin
delete from YourTableName where DATEDIFF(dd,Date_Announced,[date])>=205
end
 
 
--run abov proc
exec deleteRecords

Open in new window

0
 
LVL 1

Author Comment

by:hubfub
ID: 24409805
HI RiteshShah

DATEDIFF is not a command that is recognised nor is it a field. Is there a way to get around this? One field in ours is Date and the other is Date_Announced. What is dd?
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409811
DATEDIFF is a date function built in in SQL Server, "DD" gives you difference in days.

can't you even run below command?



select DATEDIFF(dd,getdate()-250,getdate())

Open in new window

0
 
LVL 1

Author Comment

by:hubfub
ID: 24409837
When I run that command it says 'syntax error'

I am trying to run these commands in a statistics program called SAS although the command window says PROC SQL - is this why the commands are not running?
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24409985
those command should run in SQL Server, not familiar with PROC SQL.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In this article, we’ll look at how to deploy ProxySQL.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question