这里的第一个字母应该是一个字母,列可以包含任意数量的数据,用“ /”分隔,对于每个我想要的字母,第一个字母之后可以包含3或4个字母。如何动态执行此操作。
我在考虑...首先我可以找到“ /”的位置并将其添加到一个位置,这里我们将获得字母位置,然后可以检查它是字母还是数字字符
答案 0 :(得分:0)
您应该接受有关规范化的评论-但是,您应该能够在没有UDF的情况下执行此操作。
CREATE TABLE #T
(
Flag VARCHAR(100) CHECK (
/*Only contains alpha, digits and slash*/
Flag NOT LIKE '%[^a-zA-Z0-9/]%' COLLATE Latin1_General_100_BIN2 AND
/*Doesn't end in a slash*/
Flag NOT LIKE '%/' AND
/*Start of the string and every slash should be followed by an alpha*/
'/' + Flag NOT LIKE '%/[^a-zA-Z]%' COLLATE Latin1_General_100_BIN2 AND
/*Should never have a digit immediately followed by an alpha*/
Flag NOT LIKE '%[0-9][a-zA-Z]%' COLLATE Latin1_General_100_BIN2 AND
/*Should never have two alpha in a row*/
Flag NOT LIKE '%[a-zA-Z][a-zA-Z]%' COLLATE Latin1_General_100_BIN2 AND
/*Should never have 5 digits in a row*/
Flag NOT LIKE '%[0-9][0-9][0-9][0-9][0-9]%' COLLATE Latin1_General_100_BIN2 AND
/*Should not have codes of less than 4 characters*/
'/' + Flag + '/' NOT LIKE '%/_/%' AND
'/' + Flag + '/' NOT LIKE '%/__/%' AND
'/' + Flag + '/' NOT LIKE '%/___/%'
)
);