I have a table with PostalCode Column that type’s is Char(10), I use the following Select query:
SELECT [Fm].[Id], [Sdp].[FirstName], [Sdp].[LastName], [Sdp].[SSN],
[Sdp].[StoreName],
case when isnumeric([Sdp].[PostalCode]) = 1 then CONVERT(CHAR(10),[Sdp].[PostalCode])
else '0' end, [Fc].[Id], [Sdp].[Address]
FROM [SRM].[SiteMembers].[DProfile] AS [Sdp]
INNER JOIN [SRM].[SiteMembers].[Member] AS [Sm]
ON [Sdp].[Member_Id] = [Sm].[Id]
INNER JOIN [FRM].[Members].[Member] AS [Fm]
ON [Sm].[UserId] = [Fm].[UserId]
INNER JOIN [SRM].[General].[City] AS [Sc]
ON [Sdp].[City_Id]=[Sc].[Id]
INNER JOIN [FRM].[General].[City] AS [Fc]
ON [Fc].[Title]=[Sc].[Title]
COLLATE SQL_Latin1_General_CP1_CI_AS
Whit this script the Over flow error raised like this:
Msg 248, Level 16, State 1, Line 2
The conversion of the varchar value '4153675759' overflowed an int column.
I ask a question here and I don’t want back to past with 2 scripts, So is there any way to check the PostalCode is numeric (and I mean numeric not int) without any error?
If you want to check that a
(n)(var)charvalue consists of digits and only digits, then a simply double negativeLIKEwill work:which will only be true if there are no non-digits within the string.