Click here to Skip to main content
15,886,816 members
Please Sign up or sign in to vote.
2.60/5 (5 votes)
i have tabel with this data
ID NUM
1 1
2 4
3 5
4 6
5 7
6 10
7 3
8 5
9 9
10 11
12 13

now i wanna query how will return this colons
ID Num
2 4
5 7
10 11
11 12
12 13

that what i need to return is the first and last number of numbers how are in array
exp. if we have 3 5 6 7 8 10 i need the return the 5 and 8
sorry for my bad english
thnx alot for help
Posted
Updated 16-Mar-13 2:39am
v5
Comments
Santhosh Kumar Jayaraman 30-Aug-12 2:52am    
Your question is not clear ?How can you expect 5,7 to be printed when its in sequence
nika2008 30-Aug-12 3:00am    
what information u need for more clear to be?
Santhosh Kumar Jayaraman 30-Aug-12 3:07am    
check your input and output and the scenario you said..Its not at all matching
Zoltán Zörgő 30-Aug-12 2:56am    
Ok, but you need to do this in SQL, or in C#? Actually I can not imagine a standard query statement, that can do this for you. A logic is needed, that can be made in C#, and with hard work also in an SQL server stored procedure also.
nika2008 30-Aug-12 2:59am    
i need it on sql i done query who return the array of numbers that will return me the 5 6 7 8 but i cant modifat it to give me the first and last??
any suggestrion

 
Share this answer
 
Comments
nika2008 30-Aug-12 5:43am    
dude thnx alot this is what i need
Arunprasath Natarajan 30-Aug-12 12:55pm    
:)
first make a string of Nums u want to fetch from sql.
eg.
C#
string Nums = "5,8";


sql query is like below
SQL
select * from tbl where Num in (5,8)


equivalent C# code
C#
cmd.commandtext = "select * from tbl where Num in (" + Nums + ")";
// where 'Nums' is variable having list of selected numbers separated by comma 

Happy Coding!
:)
 
Share this answer
 
v2
Comments
Legor 30-Aug-12 4:51am    
As far as it's understandable from OPs explanation this should be right.
Aarti Meswania 30-Aug-12 4:53am    
Thank you! :)
nika2008 30-Aug-12 4:55am    
i dont think so. i dont need filter 5 and 8 i need first and last elemnt who are in array for exp 6 2 7 8 9 10 6 9 and as return is 7 and 10

need the firs and last of numbers who are 7 8 9 10 and return 7 and 10
Aarti Meswania 30-Aug-12 5:01am    
I have tried my best to help you,
that isn't my fault if you can not explain your requirements clearly.
just see comments below question we all want to help you but still your question is not clear as per our last three comments below your Question I can only understand which i have explained in my answer.
this way how could anyone help you?
Legor 30-Aug-12 5:02am    
Im sorry i realy try to understand what you mean but i just dont get it.
And the 5,8 of this solution was just an example... the author was making the assumption you allready got those values beforehand.

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