| |

VerySource

 Forgot password?
 Register
Search
View: 1274|Reply: 5

I can't write such a simple sentence, I'm depressed

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-16 14:30:01
| Show all posts |Read mode
declare @pagesize varchar(10)-----Display the size of each page of data
declare @pageindex varchar(20)-----current index page
declare @testtime datetime -------Establish test time
select @pagesize=10,@pageindex=9000,@testtime=getdate()

declare @sql nvarchar(1000)
set @sql='select top'+@pagesize+' *,datediff(ms,'+cast(@testtime as varchar(30))+',getdate()) from #testtable where tid not in (select top'+cast (@pagesize * (@pageindex-1) as varchar(30))+' a.tid from #testtable a order by a.tid desc) order by tid desc'
exec (@sql)
-------------------------------------------------- -------------
I remove the sentence datediff(ms,'+cast(@testtime as varchar(30))+',getdate()) and it's fine. I want to count the query time, how to write it? ? Note that the query time may be very small! !
Reply

Use magic Report

0

Threads

48

Posts

30.00

Credits

Newbie

Rank: 1

Credits
30.00

 China

Post time: 2020-12-16 14:45:01
| Show all posts
datediff(ms,'''+cast(@testtime as varchar(30))+''',getdate())
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-16 15:00:01
| Show all posts
Is it really okay, don’t you understand? ? Why add''? ? ? ? ?
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-12-16 15:15:01
| Show all posts
Try:
set @sql='select top'+@pagesize+' *,datediff(ms,'''+cast(@testtime as varchar(30))+''',getdate()) from #testtable where tid not in (select top'+cast(@pagesize * (@pageindex-1) as varchar(30))+' a.tid from #testtable a order by a.tid desc) order by tid desc'
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-16 15:30:01
| Show all posts
Use quotation marks
Because what you passed in is a string of time, it must be enclosed in single quotes
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-12-16 15:45:01
| Show all posts
select top 10 *,datediff(ms,01 6 2017 1:14PM,getdate()) from #testtable where tid not in (select top 89990 a.tid from #testtable a order by a.tid desc) order by tid desc

Take out your SQL analysis, datediff(ms,01 6 2017 1:14PM,getdate()), there are two single quotes missing in the middle, so single quotes should be added, and in the dynamic statement, two single quotes replace one apostrophe
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