在编写存储过程的时候,遇到拼接字符串需要加单引号,浪费了点时间,现在写出来以备后用,(提醒自己别忘了这么简单的事)
变量定义时间类型的,定义为字符串类型,例子如下:
Create PROCEDURE dbo.Student
(
@Level int,
@ClassName varchar(1000),
@Start varchar(50),
@End varchar(50)
)
AS
declare @sql nvarchar(1000)
set @sql='select * from Student
where status=0 and Level='+str(@Level )+' and ClassName=@ClassName and (DateTime between '' ' +@OutDaStart eStart+' '' and '' '+@End +''')
order by datetime'
exec sp_executesql @sql
RETURN
sql语句是自己随便写的,主要是记住怎么添加单引号。