在SQL存储过程中给条件变量加上单引号,不加语句就会出问题,以下就是在存储过程中将条件where设置成了动态变化的,给where赋完值再和前面的语句拼接,再execute(SQL) ), )), )+''',sdate)<=0) and ' +' shopid='''+@shopid+''' and VenderID in ' +' (select vender from tableB where vendertype=''类型'' and shopid='''+@shopid+''')' --
sql 语句中使用条件判断case then else end范例: SELECT les.[nLessonNo] FROM BS_Lesson AS les WHERE les.[sClassCode] = 'BJ13Q2429' AND (case when les.[sRealTeacherCode]<>'' then les.[sRealTeacherCode] else les.[sTeacherCode] end )= 'xxxxx' order by les.[nLessonNo