September 6, 2006 at 3:32 pm
Michael
September 6, 2006 at 4:13 pm
If you are not specifying order by clause in your select statement data will not sorted in any order, it will fetch as it was inserted into the table
There is no such statement in SQL, which orders the result set by values in column
If you still needs it
Split your input using fn_split function (you can find this in this forum)
write as many selects as input count (use dynamic sql) , use union to combine them in that order
September 6, 2006 at 4:24 pm
Try this:
select * from stores WHERE Stor_ID IN (7067,6380,8042,7896)
order by CharIndex(stor_id,'7067,6380,8042,7896')
September 6, 2006 at 4:41 pm
sorry, not working
CharIndex will give you the starting position of the specified expression in a character string
In order by clause if you specify an integer value (returned by CharIndex funtion), the output will be ordered by the specified column position in select statement , If there is no such position in select , then it will result to default order
I think this will help
September 6, 2006 at 6:46 pm
I'm just gonna take a guess and say that you didn't actually try it Gopi... works fine from what I can see...
stor_id stor_name stor_address city state zip
------- --------------------- --------------------- ------------ ----- -----
7067 News & Brews 577 First St. Los Gatos CA 96745
6380 Eric the Read Books 788 Catamaugus Ave. Seattle WA 98056
8042 Bookbeat 679 Carson St. Portland OR 89076
7896 Fricative Bookshop 89 Madison St. Fremont CA 90019
(4 row(s) affected)
--Jeff Moden
Change is inevitable... Change for the better is not.
September 6, 2006 at 6:51 pm
Michael,
That means that, using Sreejith's fine example, your code should look something like this...
--Jeff Moden
Change is inevitable... Change for the better is not.
September 6, 2006 at 7:03 pm
Jeff,
Just now I tried again with same query, I got it ..here in example anID should be of character type, if it is of integer type query is not compiling at all
Thanks
September 6, 2006 at 7:46 pm
Yep... I believe you are correctm Gopi... didn't realize the Stor_ID in the Stores table of PUBS was actually a CHAR(4).
Soooooo..... the correct code should look something more like this if anID is an INT...
--Jeff Moden
Change is inevitable... Change for the better is not.
September 7, 2006 at 10:09 am
THANK YOU! THANK YOU!
I have racked my brain trying to find a solution.
Very much appreciated!
Michael
September 7, 2006 at 6:18 pm
Our pleasure... thanks for the feedback...
Sreejith... nice job... you hit the nail on the head... I just played "cleaning lady" on this one.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply