2017-07-26 99 views
-4

我有兩個表格A1和A2。 表A1有列轉移索引,日期和金額,A2表有列轉移索引,名稱和年齡。SQL查詢找到數據

1.如何找到當月的shift-index數據。如果我選​​擇shift-index 6,則應該填充6之前的數據。 移位指數表示日期

data

+3

似乎很大。什麼東西阻止你? –

+0

尋找解決方案..如何做到這一點 –

回答

0

我想這你想要做什麼:

where datecol >= dateadd(day, 1 - day(getdate()), cast(getdate() as date) and 
     datecol < cast(getdate() as date) 

這將返回所有行日期之間的第一當月和昨天的。在本月的第一天,它不返回任何行。

0

你也可以做這樣的事情

select * from YourTable 
where YourDateColumn between 
        DATEADD(month, DATEDIFF(month, 0, getDate()), 0) and getDate() - 1 

只需用日期值替換getDate(),並給它一個去