So here is the problem that I am in: Below is a query that I am working on in SQL:
所以这就是我所处的问题:下面是我在SQL中处理的一个查询:
SELECT top 1 FILE_DATE_PROCESSED, DATE_ENTERED
FROM FILE_DATE_PROCESSED
order by DATE_ENTERED DESC
What this is supposed to do is supposed to give me the last date from date_entered, and then date_entered is supposed to be the current date time, however it is not really doing what I asked. Below is the results that I am looking for:
这应该做的应该是给我从date_entered的最后日期,然后date_entered应该是当前的日期时间,但它并没有真正做我的要求。以下是我要找的结果:
If the this was the table that was made previously:
如果这是之前制作的表格:
FILE_DATE_PROCESSED DATE_ENTERED
2015-12-31 19:32:45.000 2015-06-09 14:26:34.360
This needs to be the next table:
这需要成为下一个表格:
FILE_DATE_PROCESSED DATE_ENTERED
2015-06-09 14:26:34.360 2015-06-11 9:16:28.344
I am not sure if it something that can be done possibly as a query, or if it has to be done in VS using c#, but one way or another please help!
我不确定它是否可以作为查询完成,或者是否必须使用c#在VS中完成,但是请帮助这样或那样!
3 个解决方案
#1
1
If you want values to change for a specific row, you should use an update statement.
If your table only contains one row, you can do it like this:
如果要为特定行更改值,则应使用update语句。如果您的表只包含一行,您可以这样做:
UPDATE FILE_DATE_PROCESSED
SET FILE_DATE_PROCESSED = DATE_ENTERED,
DATE_ENTERED = GETDATE()
That being said, you really must read an sql tutorial if you want to do anything in sql.
话虽这么说,如果你想在sql中做任何事情,你真的必须阅读一个SQL教程。
#2
1
If I understand correct, you are looking something like:
如果我理解正确,你看起来像:
INSERT INTO yourTable
(FILE_DATE_PROCESSED, DATE_ENTERED)
SELECT top 1 DATE_ENTERED,GETDATE() order by DATE_ENTERED DESC
FROM yourTable
#3
1
Probably you are looking for something like this:
可能你正在寻找这样的东西:
Select top 1 Date_Entered,
Getdate() as FILE_DATE_PROCESSED
from yourtable
order by Date_Entered desc
#1
1
If you want values to change for a specific row, you should use an update statement.
If your table only contains one row, you can do it like this:
如果要为特定行更改值,则应使用update语句。如果您的表只包含一行,您可以这样做:
UPDATE FILE_DATE_PROCESSED
SET FILE_DATE_PROCESSED = DATE_ENTERED,
DATE_ENTERED = GETDATE()
That being said, you really must read an sql tutorial if you want to do anything in sql.
话虽这么说,如果你想在sql中做任何事情,你真的必须阅读一个SQL教程。
#2
1
If I understand correct, you are looking something like:
如果我理解正确,你看起来像:
INSERT INTO yourTable
(FILE_DATE_PROCESSED, DATE_ENTERED)
SELECT top 1 DATE_ENTERED,GETDATE() order by DATE_ENTERED DESC
FROM yourTable
#3
1
Probably you are looking for something like this:
可能你正在寻找这样的东西:
Select top 1 Date_Entered,
Getdate() as FILE_DATE_PROCESSED
from yourtable
order by Date_Entered desc