As the following statements, @start and @end are the parameters of the date type
Set @sql='SELECT * from'+cast(@viewName as nvarchar)+'where Rcy_rq >='+CONVERT(nvarchar( -),@start,121)+'and Rcy_rq <='+CONVERT(nvarchar( -),@end,121)
The SQL statements entered at execution time are as follows:
Select * fromview2010whereRcy_rq>= .- A- in xx:xx:00.000and Rcy_rq <= .- A- to xx:xx:00.000
How to place single quotation marks (') on the two times of the date?
Someone on the internet said to use the other words multibyte to the desired position, and then replace with the Replace function to single quotation marks, I think this can be handled as follows:
Declare @point nvarchar (5) Set @point = Char (a)-single quotation mark
The SQL statement is changed as follows:
Set @sql='SELECT * from'+cast(@viewName as nvarchar)+'where Rcy_rq >='+@point+CONVERT(nvarchar( -),@start,121)+@point+'and Rcy_rq <='+@point+CONVERT(nvarchar( -),@end,121)+@point
It's a perfect solution to the problem.
How to add a single quotation mark to a date parameter in SQL