dns - Combine data types in SQL Server -


is there way combine data types in sql server? i.e. have value of cell both text , number text same?

i have table called contract. contractid field should have value of: 'tcwxyz' 'tc' string characters , 'wxyz' integers.

i have following doesn't seem working:

create type tenantcontracts char(6) check (substring(value,1,2)='tc' , (substring(value,2,4) smallint) 

any assistance appreciated.

constraints added table definition, don't need create type.

alter table contract add constraint chk_contractid check (     substring(contractid, 1, 2) = 'tc'     , isnumeric(substring(contractid, 3, 4)) = 1 ) 

this solution accept few incorrect values, instance tc1.01. i'd use virtue of simplicity though, rather trying determine if last 4 digits integer, gets surprisingly tricky (t-sql - determine if value integer).

edit: if did want make more robust integer check, perhaps best check individually if each of last 4 characters numeric:

alter table contract add constraint chk_contractid check (     substring(contractid, 1, 2) = 'tc'     , isnumeric(substring(contractid, 3, 1)) = 1     , isnumeric(substring(contractid, 4, 1)) = 1     , isnumeric(substring(contractid, 5, 1)) = 1     , isnumeric(substring(contractid, 6, 1)) = 1 ) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -