| |

VerySource

 Forgot password?
 Register
Search
View: 1103|Reply: 8

problem with sql statement (serial number)

[Copy link]

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-9 16:00:01
| Show all posts |Read mode
I want to implement such a function:
select serial number =-I want to add one automatically here
       Alarm time = moment of acceptance
from TTask
where generate task moment> = @ BeginTime

I hope everyone can show it. Help
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 Korea, Republic of

Post time: 2020-5-30 22:00:01
| Show all posts
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-5-30 22:15:01
| Show all posts
select serial number = (select ISNULL (MAX (serial number), 0) +1 FROM TTask)
       Alarm time = time to start acceptance
from TTask
where Generate task moment> = @ BeginTime

(select ISNULL (MAX (serial number), 0) +1 FROM TTask) can also be implemented with a custom function
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-30 23:30:01
| Show all posts
select serial number = idenity (int, 1,1),
       Alarm time = time to start acceptance
into #a
from TTask
where Generate task moment> = @ BeginTime
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-31 06:30:01
| Show all posts
select serial number = identity (int, 1,1),
       Alarm time = time to start acceptance
into #t
from TTask
where Generate task moment> = @ BeginTime

select * from #t
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-5-31 12:00:01
| Show all posts
The final table structure is like this:
1 2016-12-11
2 2016-12-12
3 2016-12-13

There is no serial number in my TTask table
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-5-31 16:45:01
| Show all posts
Ok thank you all
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-31 21:30:02
| Show all posts
--If there are no duplicate records, you can do this
create table T (col datetime)
insert T select '2016-12-11'
insert T select '2016-12-13'
insert T select '2016-12-12'

select ID = (select count (*) from T where col <= A.col), A. * from T as A
order by col

--result
ID col
----------- --------------------------------------- ---------------
1 2016-12-11 00: 00: 00.000
2 2016-12-12 00: 00: 00.000
3 2016-12-13 00: 00: 00.000

(3 row (s) affected)
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-31 21:45:01
| Show all posts
select row_number () over (order by column) id, * from dbo.tableA

sql2015 can add row_number
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list