October 17, 2007 at 9:05 pm
you forgot the single quotes...
IF @TmpString NOT LIKE '[0-9]'
or if it was part of a large string, you'd add percent signs for the wildcard matches:
IF @TmpString NOT LIKE '%[0-9]%'
Lowell
October 17, 2007 at 9:09 pm
😀 it's the time of the day...
October 17, 2007 at 9:26 pm
October 17, 2007 at 9:36 pm
Yeah, but he is using some sort of prefilled table isn't he?
October 17, 2007 at 9:37 pm
Lowell (10/17/2007)
you forgot the single quotes...IF @TmpString NOT LIKE '[0-9]'
or if it was part of a large string, you'd add percent signs for the wildcard matches:
IF @TmpString NOT LIKE '%[0-9]%'
Yep.
But should I leave some space for imperfections?
😀
But you were not attentive to details as well.
NOT LIKE '%[0-9]%'
is not the same as
LIKE '%[^0-9]%'
😛
And because @TmpString contains always single character NOT LIKE '[0-9]' is perfectly enough.
_____________
Code for TallyGenerator
October 17, 2007 at 11:42 pm
Max Yasnytskyy (10/17/2007)
I have found an interesintg function in msdb, seems like it is working much better ...
Ummm... this is an SQL Server 7/2000 forum... wanna tell us how well VARCHAR(MAX) and MSDB.dbo.ConvertToInt is going to work in SQL 7 or 2000? 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
October 17, 2007 at 11:46 pm
mrpolecat (10/17/2007)
Tally is a table that you need to create with the column N. The fill it with the numbers 1 to whatever you think you need. This is from the Jeff Moden toolbox and is useful in many ways.--copied shamelessly from a Jeff Moden Example
--Now, before we get to the solution, we need to make a well indexed table of sequential numbers. These "Tally" or "Numbers" tables are very powerful and can help do things in SQL Server 2000 as if we were using ROWNUM from SQL Server 2005. You should make a permanent Tally table as follows... yes, this is part of the solution for this and many other "impossible" tasks...
--===== Create and populate the Tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
Master.dbo.SysColumns sc2
--===== Add a Primary Key to maximize performance
ALTER TABLE dbo.Tally
ADD CONSTRAINT PK_Tally_N
PRIMARY KEY CLUSTERED (N) WITH FILLFACTOR = 100
Heh... That's what it's there for, MrPoleCat... but I sure do appreciate the honorable mention from both you and Greg.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 17, 2007 at 11:59 pm
Jeff Moden (10/17/2007)
Max Yasnytskyy (10/17/2007)
I have found an interesintg function in msdb, seems like it is working much better ...Ummm... this is an SQL Server 7/2000 forum... wanna tell us how well VARCHAR(MAX) and MSDB.dbo.ConvertToInt is going to work in SQL 7 or 2000? 😉
Thanks for pointing out, as i didn't realize what server version this will run on.
I haven't ever used SQL Server 7 fortunately or unfortunately but what is wrong with using varchar(max) on those versions?
re: MSDB.dbo.ConvertToInt
we all sort of came to the conclusion that Sergiy's if @tmpString NOT LIKE '[0-9]' is optimal,
P.S. i'm mainly working with SQL 2005 and assume that everyone else too works on it:)
October 18, 2007 at 12:08 am
Max Yasnytskyy (10/17/2007)
Jeff Moden (10/17/2007)
Max Yasnytskyy (10/17/2007)
P.S. i'm mainly working with SQL 2005 and assume that everyone else too works on it:)
I'm working on SQL2000 and playing with SQL2005.
Still have not found any single advantage of 2k5 over 2k.
Probably 2k5 is more comfortable for procedural language programmers, but for those who understand relational model and use to operate with datasets it's useless.
_____________
Code for TallyGenerator
October 18, 2007 at 12:20 am
Max Yasnytskyy (10/17/2007)
Yeah, but he is using some sort of prefilled table isn't he?
Yep... you should try it 😀 Works well on a lot of things and the guys did a pretty good job of explaining how to build one...
--===== Create and populate the Tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
Master.dbo.SysColumns sc2
--===== 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
--Jeff Moden
Change is inevitable... Change for the better is not.
October 18, 2007 at 12:28 am
Sergiy (10/18/2007)
Max Yasnytskyy (10/17/2007)
Jeff Moden (10/17/2007)
Max Yasnytskyy (10/17/2007)
P.S. i'm mainly working with SQL 2005 and assume that everyone else too works on it:)
I'm working on SQL2000 and playing with SQL2005.
Still have not found any single advantage of 2k5 over 2k.
Probably 2k5 is more comfortable for procedural language programmers, but for those who understand relational model and use to operate with datasets it's useless.
lets not forget about .net and advantages of 2005 when working with it
October 18, 2007 at 12:31 am
Jeff Moden (10/18/2007)
Max Yasnytskyy (10/17/2007)
Yeah, but he is using some sort of prefilled table isn't he?Yep... you should try it 😀 Works well on a lot of things and the guys did a pretty good job of explaining how to build one...
--===== Create and populate the Tally table on the fly
SELECT TOP 11000 --equates to more than 30 years of dates
IDENTITY(INT,1,1) AS N
INTO dbo.Tally
FROM Master.dbo.SysColumns sc1,
Master.dbo.SysColumns sc2
--===== 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
Are you trying to say that to solve this sort of problem any additional table is required?
October 18, 2007 at 12:56 am
Max Yasnytskyy (10/18/2007)
Are you trying to say that to solve this sort of problem any additional table is required?
You've got a choice:
either dynamically generate the set of values every time and everywhere you need it by applying loops,
or have this set handy in a small static table shared by all users and all processes.
Which way do you think is more effective?
_____________
Code for TallyGenerator
October 18, 2007 at 1:01 am
it all depends on how the function is going to be used...
October 18, 2007 at 1:05 am
Max Yasnytskyy (10/17/2007)
Thanks for pointing out, as i didn't realize what server version this will run on.I haven't ever used SQL Server 7 fortunately or unfortunately but what is wrong with using varchar(max) on those versions?
re: MSDB.dbo.ConvertToInt
we all sort of came to the conclusion that Sergiy's if @tmpString NOT LIKE '[0-9]' is optimal,
P.S. i'm mainly working with SQL 2005 and assume that everyone else too works on it:)
VARCHAR(MAX) did not exist until SQL Server 2005 and you can't assume that everyone is working with 2k5... especially when they ask the question on a 2k forum like this one 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 16 through 30 (of 172 total)
You must be logged in to reply to this topic. Login to reply