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 |
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-12-06 : 23:55:22
|
hello all,I had a table of 10 record for my users table.Now My problem is i have record in 8th row that record i need to show as first recordlike user table 1 Patient Information Patient Information 1 H2 Patient Demographics Patient Demographics 1 P3 Languages Languages 1 P4 Race Race 1 P5 Ethnicity Ethnicity 1 P6 City City 1 P7 State State 1 P8 Zip Codes Zip Codes 1 P9 Billing Encounter Billing Encounter 1 Hin that one 8th record i need to move as first record i wrote query like this select * from users where userId = 8 union select * from users where userid != 8..It shows exact output but how need to 8th record first place permanentlyP.V.P.MOhan |
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2012-12-07 : 00:09:36
|
You need to select * from users ORDER BY <whatever the order is>with no ORDER BY clause there is no guaranteed order.You might need to introduce a sequence column so you can order your data as required. |
|
|
mohan123
Constraint Violating Yak Guru
252 Posts |
Posted - 2012-12-07 : 01:01:18
|
can u please explain me in query i can't able to find it outP.V.P.MOhan |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2012-12-07 : 01:59:33
|
[code]DECLARE @table TABLE(id int, name varchar(100))INSERT INTO @tableSELECT 1, 'Patient Information' union allSELECT 2, 'Patient Demographics' union allSELECT 3, 'Languages' union allSELECT 4, 'Race' union all SELECT 5, 'Ethnicity' union all SELECT 6, 'City' union all SELECT 7, 'State' union allSELECT 8, 'Zip Codes' union allSELECT 9, 'Billing Encounter'SELECT * FROM @tableORDER BY CASE when id = 8 THEN 1 ELSE 2 END[/code]--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-07 : 08:14:02
|
quote: Originally posted by mohan123 hello all,I had a table of 10 record for my users table.Now My problem is i have record in 8th row that record i need to show as first recordlike user table 1 Patient Information Patient Information 1 H2 Patient Demographics Patient Demographics 1 P3 Languages Languages 1 P4 Race Race 1 P5 Ethnicity Ethnicity 1 P6 City City 1 P7 State State 1 P8 Zip Codes Zip Codes 1 P9 Billing Encounter Billing Encounter 1 Hin that one 8th record i need to move as first record i wrote query like this select * from users where userId = 8 union select * from users where userid != 8..It shows exact output but how need to 8th record first place permanentlyP.V.P.MOhan
whats the need for permanently doing this change in table? why cant you retrieve the records based you your required order on the fly by means of ORDER BY------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|