How to update a row automatically when the time is right? [closed] - sql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table with 2 columns
Time Status
2015/3/10 12:00:00 NEW
What I want to do is to automatically update the Status to "On Going" when the Time comes.
How to do that? Thank you!

The normal accepted practice would be to run a periodic job (once a minute, once every five minutes, depending on your needs) with an SQL statement like:
update mytable
set status = 'ongoing'
where status = 'new'
and time < getdate()
Whether you do this with SQL Server Agent, or a scheduled task, or a service is up to you. Given it's really an SQL Server function, I'd probably opt for the first one.

Related

How does one query a database? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How does one get the first name info from a Users table, which has a first name column?
First of all welcome to the community. I suggest you read the guidelines on how to properly ask a question here and you might want to write a title that is relevant to your question.
Now to the question:
Assuming tblUsers is a table in your database and 'first_name' is a column in your table, you can use SELECT followed by the column you want to select.
Lastly, add FROM to select which table you want to select from.
So in your case it would be:
SELECT first_name FROM tblUsers;
You can read more about SELECT here

Make SQL query fail on trying to delete non-existent record [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Is there standard SQL syntax for causing query to fail when a query tries to delete a non-existent entity? E.g.
DELETE FROM entity WHERE id = 501;
does not fail, even when there is no entity with id = 501. Can it be done in cross-database way?
Depending on environment you can get deleted row count, where you can tread 0 as error.
Or you can have a trigger that raises an exception if no rows deleted.
Here is one way you can handle this in Oracle:
BEGIN
DELETE FROM test
WHERE id = 4;
IF (SQL%NOTFOUND) THEN
dbms_output.put_line('It is already gone');
END IF;
END;
/
Here is a small demo.

Need RegEx to filter dataset according to specific position in string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Want to filter dataset with SQL query using RegEx to filter entries based on the time (hour) e.g. 19:XX or 09:XX. The hour part of the string would be in position 12 and 13.
Checked a few other questions and articles, but I'm very new to this and can't figure it out. Don't know which SQL database it is, but I work with it on Google BigQuery.Thanks for your help!
Screenshot of data entries
The standard way to access the hour in a date/time is:
where extract(hour from timecol) = 19
Not all databases support extract. All should have something similar.

Simple select query running slow [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have about 1000 entries in table. It's simple table with 10 columns. Query:
SELECT * FROM my_table
server runs the query, but is processing it for a long time.
P.S. I know this is not enough info, so please comment and I will add what is needed.
Got it. Not related to SQL. Server got overflown by data. Someone was spamming it.
You can try to use TOP. For example try to select 100 rows and look if server still stucks:
SELECT TOP 100 * FROM my_table

How can make auto change in SQL Server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to make auto changes in SQL Server. I have a table which has a column [expires date]. Should I use a trigger or job for this? I want that SQL Server checks those dates every day, and if any of it is < DateTime.Now, it must change a column [IsPremium] of that row.
Add the following statement in your Daily running JOB, if you have. (Your question in unclear. As per my understanding I post this)
UPDATE <tablename> SET
IsPremium = 1
WHERE [expires date] < GETDATE()