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;