SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


subdivision on output query in server 2000


subdivision on output query in server 2000

Author
Message
raghuldrag
raghuldrag
SSC Veteran
SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)

Group: General Forum Members
Points: 288 Visits: 473
alter procedure Goals_history
(
@stuid nvarchar(22),
@startyear nvarchar(22),
@endyear nvarchar(22),
)
as
begin
select name,class,noofsubject,rank,test from @tab1
union
select name,class,subject,rank,test from @tab2
where rank is not null
and studentname=@stuid
and accodomicyear>=@startyear
and accodomicyear<=@endyear
end

OUTPUT:
class noofsubject rank test name
2 5 1 revision ravi
2 5 - monthly raju
2 5 3 midterm ravi
6 4 - monthly somu
2 5 - revision ravi

expectin outputSadrank is null means show first)
class noofsubject rank test name
6 4 - monthly somu
2 5 - monthly raju
2 5 - revision-II ravi
2 5 1 revision ravi
2 5 3 midterm ravi

(if he have rank means the output comes on subdivision how to make the query)
rhythmk
rhythmk
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1108 Visits: 1084
raghuldrag (8/28/2012)
alter procedure Goals_history
(
@stuid nvarchar(22),
@startyear nvarchar(22),
@endyear nvarchar(22),
)
as
begin
select name,class,noofsubject,rank,test from @tab1
union
select name,class,subject,rank,test from @tab2
where rank is not null
and studentname=@stuid
and accodomicyear>=@startyear
and accodomicyear<=@endyear
end

OUTPUT:
class noofsubject rank test name
2 5 1 revision ravi
2 5 - monthly raju
2 5 3 midterm ravi
6 4 - monthly somu
2 5 - revision ravi

expectin outputSadrank is null means show first)
class noofsubject rank test name
6 4 - monthly somu
2 5 - monthly raju
2 5 - revision-II ravi
2 5 1 revision ravi
2 5 3 midterm ravi

(if he have rank means the output comes on subdivision how to make the query)


Hi raghuldrag,

Please provide the DDL of tables with sample data.

--rhythmk
------------------------------------------------------------------
To post your question use below link

http://www.sqlservercentral.com/articles/Best+Practices/61537/
:-)
raghuldrag
raghuldrag
SSC Veteran
SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)SSC Veteran (288 reputation)

Group: General Forum Members
Points: 288 Visits: 473
create table tab1(name varchar,class int(22),noofsubject numeric(12),rank int(10),test varchar(22),stuid int(11),accodomicyear nvarchar(22))

create table tab2(name varchar,class int(22),noofsubject numeric(12),rank int(10),test varchar(22)),stuid int(11),accodomicyear nvarchar(22))


insert into tab1 values(' ravi',2 ,5 ,' ' ,'revision-II',002244,2011)
insert into tab2 values('ravi',2 ,5 ,' 1' ,'revision',002244,2011)


expecting output:
class noofsubject rank test name

2 5 - revision-II ravi
(sub division)2 5 1 revision ravi
ChrisM@Work
ChrisM@Work
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22127 Visits: 19709
raghuldrag (8/28/2012)
alter procedure Goals_history
...


What version of SQL Server is your database?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
ChrisM@Work
ChrisM@Work
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22127 Visits: 19709
ChrisM@Work (8/28/2012)
raghuldrag (8/28/2012)
alter procedure Goals_history
...


What version of SQL Server is your database?


OP answered in a PM, he's using SQL Server 2000.

Raghuldrag, please post in the SQL Server 7, 2000 forum section. Posting in the SS2K8 section wastes people's time as the solutions may be different and incompatible with your antique version.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search