VFP 中可以利用 ISDIGIT() 來判斷字串最左邊字元是否為數字,ISALPHA() 來判斷字串最左邊字元是否為英文字母,SQL Server內可以透過 LIKE 來達成。
CREATE FUNCTION [dbo].[ISDIGIT]
(
@string as nvarchar(250)
)
RETURNS bit
AS
BEGIN
DECLARE @true bit
IF @string LIKE '[0-9]%'
SET @true = 1
ELSE
SET @true = 0
RETURN @true
END
CREATE FUNCTION [dbo].[ISALPHA]
(
@string as nvarchar(250)
)
RETURNS bit
AS
BEGIN
DECLARE @true bit
IF @string LIKE '[A-Z]%' -- 不區分大小寫
SET @true = 1
ELSE
SET @true = 0
RETURN @true
END
SELECT Val,
'數字判斷' = CASE WHEN dbo.ISDIGIT(Val) = 1 THEN '數字' ELSE '' END,
'字母判斷' = CASE WHEN dbo.ISALPHA(Val) = 1 THEN '字母' ELSE '' END
FROM
(
SELECT '123' AS Val
UNION ALL
SELECT '456'
UNION ALL
SELECT 'ABC'
UNION ALL
SELECT 'def' -- 故意小寫
) AS T
沒有留言:
張貼留言