MSSQL Custom Function (filter string)

Source: Internet
Author: User
function | string

Create FUNCTION f_checkstring (@temp varchar (4000))
--f_checkstring is the method name
--@temp for parameter name varchar 4000 for type length
--Filtering SQL strings
RETURNS varchar (4000)
--The return type is varchar length 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),--User name
@password varchar (20)--Password
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-User name error
Else
Begin
If @status =1
Set @result =-3--account is locked
Else
Begin
If @str = @result
Set @result = 0--Login Successful
Else
Set @result =-2--Password error
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.