Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have table tblUsers with sample value

UserID Leavedate
1 01\03\2011
1 02\03\2011
1 03\03\2011
1 06\03\2011
1 10\03\2011
1 11\03\2011

I want to retrieve the result set as date range like below structure with comma separtor.If three consecutive dates comes then group it otherwise make it as single .

Excepted Result would be

userID Leavedate
1 01\03\2011 - 03\03\2011,
06\03\2011.10\03\2011 - 11\03\2011

Please give me idea on this ?
Posted
Updated 22-Mar-11 22:06pm
v2
Comments
SujaVani 6-May-11 6:28am    
I have use temp table to manipulate the data

That's actually a PITA to do. The first question is: what data type are you going to return?
You have to return a string: because you are potentially returning a range, or comma separated values.
But because you don't have a return type to indicate if the result is a single or multiple result, you have to post-process your results to work out what dates you actually have.

Mika is correct that you would have to create this as a stored procedure in order to return what you have asked for, but I would suggest that a better way might be to re-think either your database structure, or what you are doing with the data - as the returned row will need re-processing for almost any application you want to use it for.

What are you trying to achieve, that you need this?
 
Share this answer
 
Comments
Wendelius 23-Mar-11 5:58am    
Good point, 5. The only scenario I could think of is returning this set directly to a list, grid etc.
Perhaps the simplest way to do this is to create a small procedure and handle the concatenation in the procedure. Then return the result set from the procedure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900