查詢資料庫的時間是否在輸入的時間之內

2021-10-17 02:41:02 字數 1817 閱讀 2144

//新增得開始時間與結束時間都不在之前填寫得時間範圍中

wherestr +

=string

.format

(" and ( (noticestarttime <= convert(datetime, ' 00:00:00.000', 121) and noticeendtime >= convert(datetime, ' 23:59:59.999', 121) ) "

, noticestarttime)

;開始時間

wherestr +

=string

.format

(" or (noticestarttime <= convert(datetime, ' 00:00:00.000', 121) and noticeendtime >= convert(datetime, ' 23:59:59.999', 121) ) "

, noticeendtime)

;結束時間

//新增得開始時間與結束時間不能包含之前填寫得時間範圍

wherestr +

=string

.format

(" or (noticestarttime >= convert(datetime, ' 00:00:00.000', 121) and noticeendtime <= convert(datetime, ' 23:59:59.999', 121) ) )"

, noticestarttime, noticeendtime)

;開始時間,結束時間

noticestarttime開始時間

noticeendtime結束時間

partuserid 商戶id

networkid 網點id

select *

from

notice

where1=

1and partuserid =

'4735'

and networkid =

'161'

and (

( noticestarttime <=

convert

(datetime,

'2021-02-1 00:00:00.000'

,121

)and noticeendtime >=

convert

(datetime,

'2021-02-1 23:59:59.999'

,121))

or ( noticestarttime <=

convert

(datetime,

'2021-02-28 00:00:00.000'

,121

)and noticeendtime >=

convert

(datetime,

'2021-02-28 23:59:59.999'

,121))

or ( noticestarttime >=

convert

(datetime,

'2021-02-1 00:00:00.000'

,121

)and noticeendtime <=

convert

(datetime,

'2021-02-28 23:59:59.999'

,121))

)

資料庫使用邏輯刪除時在新增查詢時遇到的問題

昨天在工作的時候遇到如下的情況 現在有2張表 user doctor team member id id name team id hospital id hospital id delete delete doctor id user表存的是所有的醫生使用者,doctor team member ...

SQL查詢資料庫是否存在

在實際工作中會遇到通過sql查詢資料庫是否存在的情況,下面一些語句可以提供一些幫助,本文的語句是在sql08r2中測試的 1,查詢當前資料庫伺服器所有資料庫 select from master.dbo.sysdatabases 2,查詢資料庫是否存在 select count from maste...

在SQL2008查詢某資料庫中的列是否存在某個值

sql2008查詢某資料庫中的列是否存在某個值 create proc spfind column in db type int,型別 1為文字型別 2為數值型別 str nvarchar 100 需要搜尋的名字 as 建立臨時表存放結果 create table tbl pk int identi...