Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
int s=select isnull(max([rid]),0)+1 from roomdetails

(Note: Upto roomno 9 inserting correctly if i go 10,11 then its getting store in below row of roomno 1)

Create table roomdetails (roomno nvarchar(250))

insert into roomdetails(@roomno) values(s);
[ i am not suppose to change roomno into int]


Roomno
1
10 -- [wrongly stored here]
2
3
4
5
6
7
8
9
--[should come here]
Posted
Updated 19-Nov-12 0:29am
v3

You mean where you select rows from roomdetails 10 comes after 1 and your orderby clause is on roomno?
Is your roomno an integar column? If not, then this will happen. For sorted string, it is 10 after 1 and not 2.
 
Share this answer
 
Comments
__TR__ 19-Nov-12 5:56am    
My 5!
MT_ 19-Nov-12 5:59am    
Thanks. :-)
Umapathi K 19-Nov-12 6:20am    
you are correct roomno in nvarchar. but i am not suppose to change into int., how to handle this
MT_ 19-Nov-12 6:24am    
I think a CAST in the order by clause should work order by cast(roomno as int)
If it doesn't paste your query in the question using "Improve Question". If it helps, mark the answer as solution and/or upvote.
Why not you selecting the record using order by clause?

SQL
Select [rid] From roomdetails Order By [rid]
 
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