使用getdate存储datepart的过程

时间:2017-02-24 07:19:26

标签: sql sql-server

SELECT 
    sr.InsertedDate AS SMSDateTime, 
    sib.MessageText AS SMS_Text, sib.Remarks
FROM 
    SMSInbound sib                            
INNER JOIN
    SMSReceived sr ON sr.ReceivedId = sib.ReceiveId
WHERE 
    sib.MessageType LIKE '%ER%'
    AND datepart(day,sr.InsertedDate) = @Day
    AND datepart(month,sr.InsertedDate) = @Month
    AND datepart(year,sr.InsertedDate) = datepart(year, getdate()).Replace("@Day", day).Replace("@Month", Month);

我要尝试编写此查询的存储过程,但是这行

AND datepart(year,sr.InsertedDate) = datepart(year,getdate()).Replace("@Day", day).Replace("@Month", Month);

导致datepart(year,getdate())

出错

有人愿意提供帮助,我们将不胜感激。

0 个答案:

没有答案