1

Topic: How to write function?

Good afternoon
The request answers on  a question:
In mssql 2005 there is a type table
[name datetime data]
It is necessary to take time at an o'clock from this table value data lines with name ' xxx'
And to interpose into the same table a new line with name ' yyy ' with taken earlier data and leaking datetime
I understand normal requests as to do, and that something to something to appropriate - never faced.

2

Re: How to write function?

harbor wrote:

good afternoon
The request answers on  a question:
In mssql 2005 there is a type table
[name datetime data]
It is necessary to take time at an o'clock from this table value data lines with name ' xxx'
And to interpose into the same table a new line with name ' yyy ' with taken earlier data and leaking datetime
I understand normal requests as to do, and that something to something to appropriate - never faced.

And at what here function?
Esteem about normal request Update, there all is written.

3

Re: How to write function?

You read without fail about:
1) procedures - in procedure you will describe the logic of change of the data
2) temporary tables - you will store the data in the temporary table for intermediate
3)  -  will be under the schedule created by you  procedure in which you is registered business of the logician.
FUNCTION is not necessary to you, function in terms T-SQL cannot modify the data in tables.

4

Re: How to write function?

To me it is necessary not UPDATE, and INSERT probably
With procedures I will understand later. And here is how to take table single line, to alter it and to interpose into another I will not think.
If someone throws an example well, well is not present further itself I will dig smile

5

Re: How to write function?

So, there are two tables t1 and t2 with structure
num, time, data
Created temporal basis TEMP c the same structure
Into it hammered in a line
n11, 12:55, 0
I write the code
USE Base
UPDATE TEMP
SET DATA=t1.DATA
WHERE (num = ' n11 ')
Writes error The multi-part identifier "t1.DATA" could not be bound.

6

Re: How to write function?

harbor wrote:

so, there are two tables t1 and t2 with structure
num, time, data
Created temporal basis TEMP c the same structure
Into it hammered in a line
n11, 12:55, 0
I write the code

USE Base
UPDATE TEMP
==> SET DATA =>>> t1. <<<DATA - That such t1 in your request???
WHERE (num = ' n11 ')

Writes error The multi-part identifier "t1.DATA" could not be bound.

7

Re: How to write function?

harbor;
For "just in case" - the documentation on UPDATE esteem not to invent own syntax, and to use that is accepted in MS a SQL Server

8

Re: How to write function?

harbor;
If laziness to read all article about UPDATE read at least that part that concerns update of the data of one table on the basis of the data of other table....

9

Re: How to write function?

harbor wrote:

To me it is necessary not UPDATE, and INSERT probably

well and about INSERT do not forget to esteem

10

Re: How to write function?

Made while so
USE Base
UPDATE t1
SET [DATA] =a. [DATA]
FROM t2 an INNER JOIN t1 b ON a. NUM =b. NUM
Errors are not present now.

11

Re: How to write function?

In general it made
But I do not know how to launch now the job each hour with offset 5 minutes
That is 16-05, 17-05 etc.

12

Re: How to write function?

harbor wrote:

in general it made
But I do not know how to launch now the job each hour with offset 5 minutes
That is 16-05, 17-05 etc.

In Job, certainly. If not Express Edition, certainly.

13

Re: How to write function?

starts exactly from the beginning of each hour
In the job registered in the code beginning

waitfor delay ' 00:05'

5 minutes before master code performance//should wait

14

Re: How to write function?

harbor wrote:

  starts exactly from the beginning of each hour
In the job registered in the code beginning

waitfor delay ' 00:05'

5 minutes before master code performance//

should wait That hinders to set start exact time, instead of in the beginning of hour?

15

Re: How to write function?

iap wrote:

it is passed...
What hinders to set start exact time, instead of in the beginning of hour?

Did not find such adjustment in the schedule.

16

Re: How to write function?

harbor wrote:

it is passed...
Did not find such adjustment in the schedule.

As searched for that?
"To fulfill each hour, since 16:05" - each hour per 5 minutes will be fulfilled.

17

Re: How to write function?

Minamoto wrote:

it is passed...
How searched for that?
"To fulfill each hour, since 16:05" - each hour per 5 minutes will be fulfilled.

Tried, fulfills all the same exactly each hour
Though I set from the beginning of days from 00-05, that is it probably from next day only starts to fulfill with offset.