sqlserver通配符
Ⅰ sql中,LIKE 的 用法
SQL Server里有[^]。
楼主要的查询是
select * from A where 姓名字段 not like '[^王]%'
是就是非的非。
Ⅱ sqlserver怎么创建存储过程
SQL创建存储过程的基础语法是:
create proc | procere pro_name
[{@参数数据类型}=[默认值][output], {@参数数据类型}=[默认值][output], .... ]
as
SQL_statements
常见的创建存储过程实例如下:
1、创建不带参数的存储过程:
create proc proc_get_student
as
select*from student;
执行存储过程:
exec proc_get_student;
2、带参数的存储过程:
create proc proc_find_stu(@startId int, @endId int)
as
select*from student where id between @startId and @endId;
执行存储过程:
exec proc_find_stu 2, 4;
3、带通配符参数的存储过程:
create proc proc_findStudentByName(@name varchar(20)='%j%', @nextName varchar(20)='%')
as
select*from student where name like @name and name like @nextName;
执行存储过程:
exec proc_findStudentByName;
exec proc_findStudentByName '%o%', 't%';
4、带输出参数的存储过程:
create proc proc_getStudentRecord( @id int, -- 默认输入参数
@name varchar(20) out, -- 输出参数
@age varchar(20) output -- 输入输出参数 )
as
select @name = name, @age = age from student where id = @id and sex = @age;
执行存储过程:
declare @id int, @name varchar(20), @temp varchar(20);
set @id = 7;
set @temp = 1;
exec proc_getStudentRecord @id, @name out, @temp output;
select @name, @temp;
print @name + '#' + @temp;