1.在程序中直接使用
sqlStr = 'AppliantType=''请假'''
string sql= "Exec('select * from TableName where " + sqlStr + "')";
SQL如果直接set @StepCondition 用法类同
declare @StepCondition nvarchar(200)
set @StepCondition = 'AppliantType=''请假'''
Exec('select * from TableName where' + @StepCondition)
但是 @StepCondition 如果是存入字段中取出再用的话
就不能存AppliantType=''请假'' 而要存 AppliantType='请假'
注意引号
2.例如有个函数[dbo].[f_compare],可以用Select 或Set赋值,但是调用时要加上dbo.,否则会识别不出来
/**********取反及^符号出现的结果**************/
declare @CycleYear int
set @CycleYear =1
set @CycleYear = -@CycleYear --取反
print @CycleYear -- -1
set @CycleYear =5
set @CycleYear = @CycleYear^2 -- +2
print @CycleYear --7
set @CycleYear = @CycleYear^2 -- -2
print @CycleYear -- 5
set @CycleYear = @CycleYear^2 -- +2
print @CycleYear -- 7