Experts Exchange connects you with the people and services you need so you can get back to work.
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
FROM Master.dbo.SysColumns sc1,
--===== Add a Primary Key to maximize performance
ALTER TABLE dbo.Tally
ADD CONSTRAINT PK_Tally_N
PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100
--===== Allow the general public to use it
GRANT SELECT ON dbo.Tally TO PUBLIC
CREATE FUNCTION dbo.fnDigitsOnly (@pString VARCHAR(8000))
-- Tally table can be found at http://www.sqlservercentral.com/scripts/Advanced+SQL/62486/
RETURNS VARCHAR(8000) AS
DECLARE @CleanString VARCHAR(8000)
SELECT @CleanString = ISNULL(@CleanString,'')+SUBSTRING(@pString,N,1)
FROM dbo.Tally WITH (NOLOCK)
AND SUBSTRING(@pString,N,1) LIKE ('[0-9]')
UPDATE <table> SET field = dbo.fn_DigitsOnly(field)
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.