MSSQL Custom Function (filter string)

Source: Internet
Author: User
Tags filter mssql

Create FUNCTION f_checkString(@temp varchar(4000))
--f_checkString为方法名
--@temp为参数名 varchar为参数类型 4000为类型长度
--过滤SQL字符串
RETURNS varchar(4000)
--返回类型为varchar长度为4000
AS
BEGIN
set @temp=replace(@temp,'''','')
set @temp=replace(@temp,'"','')
set @temp=replace(@temp,':','')
set @temp=replace(@temp,'-','')
return @temp
END

--------------------------------------------------------------------------------------------

The method is invoked during the stored procedure in MSSQL as follows:

--Determine if the user name and password are correct

--exec sp_CheckUser
--2006-8-2
--dzend.com
Create PROCEDURE sp_CheckUser
@username varchar(20), --用户名
@password varchar(20) --密码
as
declare
@str varchar(20),
@result int,
@status int

--Filter illegal strings

select @username=dbo.f_checkString(@username)
select @password=dbo.f_checkString(@password)
select @str=[password],@status=status from usersInfo where username=@username
if @@rowcount=0
set @result=-1 --用户名错误
else
begin
if @status=1
set @result=-3 --帐号被锁定
else
begin
if @str=@result
set @result=0 --登陆成功
else
set @result=-2 --密码错误
end
end
select @result
GO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.