問題描述
大家好,我想在今天之前從發(fā)票和客戶中搜索數(shù)據(jù)我正在使用 DateDiff() GETDATE() 函數(shù),例如兩個(gè)表
Hello everyone i want search data from invoices and client by today date I'm using DateDiff() GETDATE() functions for example two tables
1 個(gè)客戶
- ID int
- Name Varcher
2 發(fā)票
- ID int
- ClientID int
- date Datetime
- Total money
查詢
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, getdate()) = 0
我想從日期時(shí)間按當(dāng)前月份和當(dāng)前年份的特定日期選擇查詢?nèi)绻?dāng)前月份是 08 和當(dāng)前年份 2010 我想寫一個(gè)月的任何一天謝謝大家?guī)臀?/strong>
I want select query by specific day of current month and current year from date time if the current month is 08 and current year 2010 i want write any day of month Thanks every one help me
推薦答案
從當(dāng)前月份和年份中的特定日期選擇記錄的最簡單方法是聲明一個(gè)分配給指定日期、月份和年份的 datetime 變量,以及用變量替換查詢中的 getdate()
- 像這樣:
The simplest way to select records from a specific day in the current month and year is to declare a datetime variable assigned to the specified day, month and year, and replace getdate()
in your query with the variable - like so:
declare @date datetime
select @date = '10-Aug-2010'
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, @date) = 0
要在當(dāng)前月份的指定日期運(yùn)行查詢,請嘗試以下操作:
To run a query for a specified day of the month in the current month, try the following:
declare @day integer
select @day = 10
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, dateadd(dd,@day-datepart(dd,getdate()),getdate())) = 0
這篇關(guān)于從日期時(shí)間 SQL Server 2005 當(dāng)前月份和當(dāng)前年份的特定日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!