Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ctlqt12
Starting Member
2 Posts |
Posted - 2006-10-07 : 07:58:36
|
| Hi,I have one table : Questions(QuestionId,Content) ( use MSSQL )when i executed this sql : "select * from Questions where subjectId in ('Q002','Q001','Q009','Q007')"i got these : ( it seems they were ordered by QuestionId automatically )Q001 Content_1Q002 Content_2Q007 Content_7Q009 Content_9But i don't want that. I want they will be showed like this : ( with no order by QuestionId or something ).Q002 Content_2Q001 Content_1Q009 Content_9Q007 Content_7How could i solve that? |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-10-07 : 08:07:49
|
Why you want to do like this?? try to order the data in the front end while displyaing it. from query you have to do like this which is not at all recommonded. you can not predict the order of the query, unless you have specified order by clause explicitly in your queryselect * from Questions where subjectId = 'Q002' Union All select * from Questions where subjectId = 'Q001' Union All select * from Questions where subjectId = 'Q009' Union Allselect * from Questions where subjectId = 'Q007' Chirag |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-07 : 08:19:03
|
[code]create table #Questions ( QuestionId varchar(10), Content varchar(10))insert into #Questionsselect 'Q001', 'Content_1' union allselect 'Q002', 'Content_2' union allselect 'Q007', 'Content_7' union allselect 'Q009', 'Content_9'select * from #Questions /* RESULTQuestionId Content ---------- ---------- Q001 Content_1Q002 Content_2Q007 Content_7Q009 Content_9*/select * from #Questions where QuestionId in ('Q002','Q001','Q009','Q007')order by charindex(QuestionId, 'Q002,Q001,Q009,Q007')/* RESULTQuestionId Content ---------- ---------- Q002 Content_2Q001 Content_1Q009 Content_9Q007 Content_7*/drop table #Questions[/code] KH |
 |
|
|
|
|
|
|
|