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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need a help

Author  Topic 

divyaram
Posting Yak Master

180 Posts

Posted - 2010-05-03 : 05:21:30
Hi all,


My result set is like this , here i want a free column after each
pos grp ... how i can do
Position_ID Position PosGrp
1 Bachelors Student 1
2 Master Student 1
3 Medical Student 1
4 Ph.D. Student 1
5 M.D. Student 1
6 Post Doctoral Researcher 2
7 Tenure Track 2
8 Assistant Professor 2
9 Tenured Professor 2
10 Principal Investigator 2
11 Lab Head 2
12 Laboratory Director 2
36 Senior Registrar 3
38 Senior Resident 3
26 Attending Physician 3
27 Family Physician 3
28 House Officer 3
23 School Teacher 4
24 Educator 4
25 Consultant 4
34 Nurse 4


My code is like this


SELECT Position_ID ,Position,posgrp
FROM dbo.FIS_Position WITH(NOLOCK)
WHERE Status='A' AND Lang_ID = 1
ORDER BY posgrp

Regards,
Divya

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-05-03 : 05:27:22
what do you mean by Free column..?

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2010-05-03 : 05:35:51
quote:
Originally posted by karthik_padbanaban

what do you mean by Free column..?

Karthik
http://karthik4identity.blogspot.com/



soory a row should be left free like that

Regards,
Divya
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-05-03 : 05:54:26
May be this could help you to some extent.

SELECT a.posgrp,a.Position_ID ,a.Position
FROM dbo.FIS_Position a WITH(NOLOCK)
WHERE Status='A' AND Lang_ID = 1
union all
select distinct(b.posgrp),'','' from
FIS_Position b WITH(NOLOCK)
ORDER BY a.posgrp


Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2010-05-03 : 06:26:03
quote:
Originally posted by karthik_padbanaban

May be this could help you to some extent.

SELECT a.posgrp,a.Position_ID ,a.Position
FROM dbo.FIS_Position a WITH(NOLOCK)
WHERE Status='A' AND Lang_ID = 1
union all
select distinct(b.posgrp),'','' from
FIS_Position b WITH(NOLOCK)
ORDER BY a.posgrp


Karthik


hi karthik,
Thank for your help, but this query wnt satisfy my requirement i am getting output
like this when i use this query


1 1 Bachelors Student
1 5 M.D. Student
1 0
2 0
2 33 Fellow
2 22 University Teacher
2 6 Post Doctoral Researcher
3 26 Attending Physician
3 27 Family Physician
3 38 Senior Resident
3 0
4 0
4 34 Nurse
4 35 Pharmacist

i want the output like this
1 1 Bachelors Student
1 5 M.D. Student
1 0
2 33 Fellow
2 22 University Teacher
2 6 Post Doctoral Researcher
2 0
3 26 Attending Physician
3 27 Family Physician
3 38 Senior Resident
3 0
4 34 Nurse
4 35 Pharmacist
4 0
http://karthik4identity.blogspot.com/



Regards,
Divya
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-05-03 : 07:20:47
SELECT a.posgrp,a.Position_ID ,a.Position
FROM dbo.FIS_Position a WITH(NOLOCK)
WHERE Status='A' AND Lang_ID = 1
union all
select distinct(b.posgrp),'','' from
FIS_Position b WITH(NOLOCK)
ORDER BY a.posgrp,a.Position_ID desc

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2010-05-03 : 07:41:21
quote:
Originally posted by karthik_padbanaban

SELECT a.posgrp,a.Position_ID ,a.Position
FROM dbo.FIS_Position a WITH(NOLOCK)
WHERE Status='A' AND Lang_ID = 1
union all
select distinct(b.posgrp),'','' from
FIS_Position b WITH(NOLOCK)
ORDER BY a.posgrp,a.Position_ID desc

Karthik
http://karthik4identity.blogspot.com/



Thank you karthik it worked

Regards,
Divya
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-05-03 : 08:00:24
Welcome.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page
   

- Advertisement -