Home > database >  Consult the SQL statement
Consult the SQL statement

Time:04-15

Sometime yesterday, how do I query to the statement, some time today, for example, 8 PM to 8 PM today data yesterday, the date is not a fixed time is fixed

CodePudding user response:

 
The select list [field]
The from [table name]
Where [time] between cast (convert (varchar, getdate () - 1, 10) + '08:00:00' as a datetime)
And cast the convert (varchar, getdate (), 23) + '08:00:00' as a datetime)

CodePudding user response:

 
The select list [field]
The from [table name]
Where [time] between cast (convert (varchar (10), getdate () - 1120) + '08:00:00' as a datetime)
And cast (convert (varchar (10), getdate (), 120) + '08:00:00' as the date

CodePudding user response:

refer to the second floor yolyry response:
 
The select list [field]
The from [table name]
Where [time] between cast (convert (varchar (10), getdate () - 1120) + '08:00:00' as a datetime)
And cast (convert (varchar (10), getdate (), 120) + '08:00:00' as the date

Tests show from a string to change the date or time, conversion fails, ask

CodePudding user response:

refer to the second floor yolyry response:
 
The select list [field]
The from [table name]
Where [time] between cast (convert (varchar (10), getdate () - 1120) + '08:00:00' as a datetime)
And cast (convert (varchar (10), getdate (), 120) + '08:00:00' as the date

From the string conversion date or time, conversion failure

CodePudding user response:

reference 4 floor yalishandazhu response:
Quote: refer to the second floor yolyry response:
 
The select list [field]
The from [table name]
Where [time] between cast (convert (varchar (10), getdate () - 1120) + '08:00:00' as a datetime)
And cast (convert (varchar (10), getdate (), 120) + '08:00:00' as the date

From the string conversion date or time, conversion failure

Oh varchar unrestricted prompt syntax errors
  • Related