发布时间:2010-09-07 15:12 来源:未知
假如需要让SQL数据库中的事务和存储过程优化,SQL语句应该如何写呢?接下来的SQL server内容就将为您介绍存储过程优化的SQL语句写法,希望对您学习SQL语句的使用有所帮助。
判断插入值是否重复:
IF @UserID <> ''
BEGIN
set @strwhere = @strwhere + ' and (UserID LIKE ' + '''' + '%' + @UserID + '%' + '''' + ')'
END
IF @Type >0
BEGIN
set @strwhere = @strwhere + ' and Type = ' + CAST(@Type AS varchar(12))
END
if @strwhere <>''
BEGIN
set @strsql = @strsql + ' where ' + right(@strwhere, len(@strwhere)-4)
END
--按用户名排序
set @strsql = @strsql + ' ORDER BY Type,UserID'
exec (@strsql)
GO