sql函数 手机品牌

alter FUNCTION  GetBrand 
(
@Mobile varchar(11)
)
RETURNS int
AS
BEGIN
DECLARE @ReturnInt INT
DECLARE @SubStr VARCHAR(3)
SELECT @ReturnInt =0
SET @SubStr = substring(@Mobile,1,3)
IF(LEN(@Mobile) = 11)
begin
IF(@SubStr='133' or @SubStr='153' or @SubStr='180' or @SubStr='189' )
BEGIN
SELECT @ReturnInt =3 -- 中国电信

END

IF(@SubStr='130' or @SubStr='131' OR @SubStr='132' or @SubStr='155' or @SubStr='156' or @SubStr='185' or @SubStr='186')
BEGIN
SELECT @ReturnInt =2 -- 中国联通

END

IF(@SubStr='134' or @SubStr='135' OR @SubStr='136' or @SubStr='137' or @SubStr='138' or @SubStr='139' or @SubStr='147' or @SubStr='150' or @SubStr='151' or @SubStr='152' or @SubStr='157' or @SubStr='158' or @SubStr='159' or @SubStr='182' or @SubStr='187' or @SubStr='188')
BEGIN
SELECT @ReturnInt =1 -- 中国移动

END

END
RETURN @ReturnInt
end
GO

;
SELECT Mobile,dbo.GetBrand('13377885566') AS tt FROM dbo.Excel_Table;
posted @ 2011-12-12 13:47  心_远  阅读(263)  评论(0编辑  收藏  举报