SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Is this thing is possible with table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 12/06/2012 :  23:55:22  Show Profile  Reply with Quote
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 record
like user table

1 Patient Information Patient Information 1 H
2 Patient Demographics Patient Demographics 1 P
3 Languages Languages 1 P
4 Race Race 1 P
5 Ethnicity Ethnicity 1 P
6 City City 1 P
7 State State 1 P
8 Zip Codes Zip Codes 1 P
9 Billing Encounter Billing Encounter 1 H

in 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 permanently

P.V.P.MOhan

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 12/07/2012 :  00:09:36  Show Profile  Reply with Quote
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.
Go to Top of Page

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 12/07/2012 :  01:01:18  Show Profile  Reply with Quote
can u please explain me in query i can't able to find it out

P.V.P.MOhan
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 12/07/2012 :  01:59:33  Show Profile  Reply with Quote

DECLARE @table TABLE(id int, name varchar(100))
INSERT INTO @table
SELECT 1, 'Patient Information' union all
SELECT 2, 'Patient Demographics' union all
SELECT 3, 'Languages' union all
SELECT 4, 'Race' union all 
SELECT 5, 'Ethnicity' union all 
SELECT 6, 'City' union all 
SELECT 7, 'State' union all
SELECT 8, 'Zip Codes' union all
SELECT 9, 'Billing Encounter'

SELECT * 
FROM @table
ORDER BY CASE when id = 8 THEN 1 ELSE 2 END


--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/07/2012 :  08:14:02  Show Profile  Reply with Quote
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 record
like user table

1 Patient Information Patient Information 1 H
2 Patient Demographics Patient Demographics 1 P
3 Languages Languages 1 P
4 Race Race 1 P
5 Ethnicity Ethnicity 1 P
6 City City 1 P
7 State State 1 P
8 Zip Codes Zip Codes 1 P
9 Billing Encounter Billing Encounter 1 H

in 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 permanently

P.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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000