如何删除1个月以前的行?

时间:2015-10-29 09:19:39

标签: sql-server

我在此表中有一个表登录我想删除超过1个月的行。

  CREATE TABLE [dbo].[Login] (
  [Id]          INT           IDENTITY (1, 1) NOT NULL,
  [CurrentTime] VARCHAR(MAX) NULL,
  PRIMARY KEY CLUSTERED ([Id] ASC)
  );

这是我的表设计。这里我将日期和时间存储为varchar类型。 使用或不使用CurrenTime字段如何删除一个月的旧行

3 个答案:

答案 0 :(得分:4)

使用Bitmap bitmap = decodeFroeSomeFile(); //It's a 2M png image. ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); File result = generateFileFromStream(baos); //It's a file larger then 2M 。尝试

DateAdd

DELETE FROM Table1 WHERE Column < DATEADD(MONTH, -1, GETDATE())

要将varchar列转换为日期格式,请使用

DELETE FROM Table1 WHERE Column < DATEADD(dd,-30,GETDATE())

答案 1 :(得分:3)

                     java.lang.OutOfMemoryError
                      at com.google.android.gms.vision.Frame.zzEx(Unknown Source)
                        at   com.google.android.gms.vision.Frame.getGrayscaleImageData(Unknown    Source)
        at com.google.android.gms.vision.face.FaceDetector.detect(Unknown Source)
        at com.chat.elearnplayer.mobilevisionapi.MainActivity.onCreate(MainActivity.java:43)
        at android.app.Activity.performCreate(Activity.java:5296)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2283)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2370)
        at android.app.ActivityThread.access$800(ActivityThread.java:155)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5426)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
        at dalvik.system.NativeStart.main(Native Method)

会奏效。

答案 2 :(得分:2)

尝试:

DELETE FROM Table1 WHERE DATEDIFF(mm, CAST(COL2 AS DateTime), GETDATE()) > 1