Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
GeneralRe: Ordering names into list box Pin
Member 1374647826-Mar-18 2:52
Member 1374647826-Mar-18 2:52 
GeneralRe: Ordering names into list box Pin
OriginalGriff26-Mar-18 3:57
mveOriginalGriff26-Mar-18 3:57 
GeneralRe: Ordering names into list box Pin
#realJSOP26-Mar-18 5:27
mve#realJSOP26-Mar-18 5:27 
QuestionMin and Max or Range Pin
sunsher21-Mar-18 22:52
sunsher21-Mar-18 22:52 
AnswerRe: Min and Max or Range Pin
OriginalGriff21-Mar-18 23:04
mveOriginalGriff21-Mar-18 23:04 
AnswerRe: Min and Max or Range Pin
Gerry Schmitz22-Mar-18 9:00
mveGerry Schmitz22-Mar-18 9:00 
AnswerRe: Min and Max or Range Pin
Eddy Vluggen22-Mar-18 10:24
professionalEddy Vluggen22-Mar-18 10:24 
AnswerRe: Min and Max or Range Pin
#realJSOP23-Mar-18 2:37
mve#realJSOP23-Mar-18 2:37 
Like Griff said, that would result in some nasty SQL. Of course, the following works just fine:

SQL
-- just setting up a table so I could illustrate the necessary sql
IF OBJECT_ID('tempdb..#fruits') IS NOT NULL
    DROP TABLE #fruits

CREATE TABLE #fruits
(
    ID nvarchar(10),
    Fruit nvarchar(16)
)

insert into #fruits (ID, Fruit)
VALUES ('1', 'Apple'),
 ('2', 'Apple'),
 ('3', 'Apple'),
 ('3a', 'Apple'),
 ('4', 'Orange'),
 ('4a', 'Orange'),
 ('4b', 'Orange'),
 ('5', 'Orange')

--///////////////////////////////////////////////////////////////
-- this is the code that does what you want
--///////////////////////////////////////////////////////////////

SELECT MIN([ID]) AS MinID, MAX([ID]) AS MaxID, [Fruit] FROM [#fruits] GROUP BY [Fruit]

-- or if you want to strip the non-numeric chars
-- (warning - somewhat nasty sql ahead)

SELECT MIN(substring([ID], PATINDEX('%[0-9]%', [ID]), 1+PATINDEX('%[0-9][^0-9]%', [ID]+'x')-PATINDEX('%[0-9]%', [ID]))) AS MinID,
       MAX(substring([ID], PATINDEX('%[0-9]%', [ID]), 1+PATINDEX('%[0-9][^0-9]%', [ID]+'x')-PATINDEX('%[0-9]%', [ID]))) AS MaxID,
       [Fruit] 
FROM [#fruits] 
GROUP BY [Fruit]


Beyond that, what if the data is mixed up (the data is put into the database as apple,orange,apple,apple,orange,apple)?

Even if the data WERE ordered exactly the way you want it, what business case would find the min/max Uid as relevant data? Even if you were using a more appropriate integer ID field, it still wouldn't mean anything to anyone.

[Minor_Rant]
Programming instructors really need to start creating meaningful assignments so that a) the student doesn't learn from a basis of bad coding practice, and b) the student isn't pummeled with whacked out scenarios that would never happen in the real world.

The small amount of actual college I attended (after having been a programmer for 10 years) really ticked me off. One C++ assignment involved counting the number of a certain character in a string. I provided three different ways to do it, but I was marked down (I actually got an 'F' for the assignment) for the content of the string I used. I contested it, and got my 'A' grade, but the whole thing left me with a real sour taste in my mouth for "instructors" of any description.

[/Minor_Rant]
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013


modified 23-Mar-18 10:48am.

SuggestionRe: Min and Max or Range Pin
Richard Deeming23-Mar-18 9:19
mveRichard Deeming23-Mar-18 9:19 
GeneralRe: Min and Max or Range Pin
sunsher24-Mar-18 0:38
sunsher24-Mar-18 0:38 
GeneralRe: Min and Max or Range Pin
#realJSOP24-Mar-18 1:00
mve#realJSOP24-Mar-18 1:00 
GeneralRe: Min and Max or Range Pin
Eddy Vluggen24-Mar-18 1:05
professionalEddy Vluggen24-Mar-18 1:05 
GeneralRe: Min and Max or Range Pin
#realJSOP24-Mar-18 1:00
mve#realJSOP24-Mar-18 1:00 
GeneralRe: Min and Max or Range Pin
jsc4228-Mar-18 3:02
professionaljsc4228-Mar-18 3:02 
JokeRe: Min and Max or Range Pin
Mycroft Holmes24-Mar-18 13:14
professionalMycroft Holmes24-Mar-18 13:14 
GeneralRe: Min and Max or Range Pin
#realJSOP26-Mar-18 2:10
mve#realJSOP26-Mar-18 2:10 
AnswerRe: Min and Max or Range Pin
MadMyche26-Mar-18 6:26
professionalMadMyche26-Mar-18 6:26 
Questionasync using linq Pin
Member 1347859921-Mar-18 20:42
Member 1347859921-Mar-18 20:42 
AnswerRe: async using linq Pin
Pete O'Hanlon21-Mar-18 22:01
mvePete O'Hanlon21-Mar-18 22:01 
GeneralRe: async using linq Pin
Member 1347859921-Mar-18 22:07
Member 1347859921-Mar-18 22:07 
GeneralRe: async using linq Pin
Pete O'Hanlon21-Mar-18 23:14
mvePete O'Hanlon21-Mar-18 23:14 
GeneralRe: async using linq Pin
Member 1347859922-Mar-18 1:04
Member 1347859922-Mar-18 1:04 
AnswerRe: async using linq Pin
Gerry Schmitz22-Mar-18 9:09
mveGerry Schmitz22-Mar-18 9:09 
GeneralRe: async using linq Pin
Member 1347859922-Mar-18 20:03
Member 1347859922-Mar-18 20:03 
QuestionC# listbox Pin
Member 1373977821-Mar-18 14:42
Member 1373977821-Mar-18 14:42 

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.