Click here to Skip to main content
15,891,431 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wouldn't it be great... Pin
Richard Deeming23-Mar-18 10:24
mveRichard Deeming23-Mar-18 10:24 
GeneralRe: Wouldn't it be great... Pin
Jörgen Andersson23-Mar-18 10:29
professionalJörgen Andersson23-Mar-18 10:29 
GeneralRe: Wouldn't it be great... Pin
Jörgen Andersson23-Mar-18 11:53
professionalJörgen Andersson23-Mar-18 11:53 
GeneralRe: Wouldn't it be great... Pin
Slacker00723-Mar-18 10:35
professionalSlacker00723-Mar-18 10:35 
GeneralRe: Wouldn't it be great... Pin
Richard Deeming23-Mar-18 10:41
mveRichard Deeming23-Mar-18 10:41 
GeneralRe: Wouldn't it be great... Pin
RickZeeland23-Mar-18 10:56
mveRickZeeland23-Mar-18 10:56 
GeneralRe: Wouldn't it be great... Pin
#realJSOP23-Mar-18 11:19
mve#realJSOP23-Mar-18 11:19 
GeneralRe: Wouldn't it be great... Pin
PIEBALDconsult23-Mar-18 17:38
mvePIEBALDconsult23-Mar-18 17:38 
Something like this (slightly tested) should show that he didn't do it himself:

SQL
WITH [cte0] AS
(
  SELECT [Fruit]
  , [ID]
  , PATINDEX ( '%[0-9]%'       , [ID] ) [start]
  , PATINDEX ( '%[0-9][^0-9]%' , [ID] ) [end]
  FROM [#fruits]
)
, [cte1] AS
(
  SELECT [Fruit]
  , [ID]
  , SUBSTRING ( [ID] , [start] , CASE WHEN [end] = 0 THEN LEN ( [ID] ) ELSE [end] END ) [numeric]
  FROM [cte0] 
)
SELECT MIN ( [numeric] ) AS MinID
, MAX ( [numeric] ) AS MaxID
, [Fruit] 
FROM [cte1] 
GROUP BY [Fruit]



I also have a table-valued CLR function that uses Regular Expressions, which would suit the assignment.

That would be something like:

SQL
SELECT MIN ( B.[Match] ) AS MinID
, MAX ( B.[Match] ) AS MaxID
, A.[Fruit] 
FROM [#fruits] A
CROSS APPLY Library.dbo.RegEx ( [ID] , '^\d+' ) B
GROUP BY A.[Fruit]


modified 23-Mar-18 23:56pm.

GeneralRe: Wouldn't it be great... Pin
PIEBALDconsult23-Mar-18 18:46
mvePIEBALDconsult23-Mar-18 18:46 
GeneralRe: Wouldn't it be great... Pin
jschell24-Mar-18 7:36
jschell24-Mar-18 7:36 
GeneralRe: Wouldn't it be great... Pin
PIEBALDconsult25-Mar-18 10:40
mvePIEBALDconsult25-Mar-18 10:40 
GeneralRe: Wouldn't it be great... Pin
jschell31-Mar-18 5:53
jschell31-Mar-18 5:53 
GeneralRe: Wouldn't it be great... Pin
Mycroft Holmes24-Mar-18 14:46
professionalMycroft Holmes24-Mar-18 14:46 
GeneralThought of the Day Pin
OriginalGriff23-Mar-18 5:50
mveOriginalGriff23-Mar-18 5:50 
GeneralRe: Thought of the Day Pin
W Balboos, GHB23-Mar-18 5:55
W Balboos, GHB23-Mar-18 5:55 
QuestionRe: Thought of the Day Pin
megaadam23-Mar-18 6:26
professionalmegaadam23-Mar-18 6:26 
AnswerRe: Thought of the Day Pin
OriginalGriff23-Mar-18 6:35
mveOriginalGriff23-Mar-18 6:35 
GeneralRe: Thought of the Day Pin
megaadam23-Mar-18 7:20
professionalmegaadam23-Mar-18 7:20 
GeneralRe: Thought of the Day Pin
lopatir23-Mar-18 7:40
lopatir23-Mar-18 7:40 
GeneralRe: Thought of the Day Pin
TNCaver23-Mar-18 11:03
TNCaver23-Mar-18 11:03 
GeneralOnline Piracy Pin
milo-xml23-Mar-18 5:20
professionalmilo-xml23-Mar-18 5:20 
GeneralRe: Online Piracy Pin
RickZeeland23-Mar-18 7:44
mveRickZeeland23-Mar-18 7:44 
GeneralRe: Online Piracy Pin
DRHuff23-Mar-18 10:47
DRHuff23-Mar-18 10:47 
GeneralRe: Online Piracy Pin
lopatir23-Mar-18 8:27
lopatir23-Mar-18 8:27 
JokeRe: Online Piracy Pin
RickZeeland23-Mar-18 9:58
mveRickZeeland23-Mar-18 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.