I have string query in and pass @Date object to string. It is giving error. See below code.
Declare @MidDate datetime, @MaxDate datetime
set @qrysales_trans_unit_26wks ='update historical_result
set sales_trans_unit_26wks = (
SELECT
SUM(sales_trans_unit)
FROM reg_summary_rowno WHERE
period_idx >= '+ @MidDate // error
+' AND period_idx <'+ @MaxDate /error
+' AND Client_id ='+ @Client_id
+' and historical_result.[store_idx] = reg_summary_rowno.[store_idx]
And [attributes] ='+ @attributes +')'
How to pass Datetime object in the proper way to string Query?
Try using two single quotes to escape quote marks so dates end up like: period_idx >= ‘@MidDate’
Click here for more information on escaping quotes in SQL.