Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
subdivision on output query in server 2000
subdivision on output query in server 2000
Rate Topic
Display Mode
Topic Options
Author
Message
raghuldrag
raghuldrag
Posted Tuesday, August 28, 2012 12:23 AM
SSC Journeyman
Group: General Forum Members
Last Login: Today @ 6:24 AM
Points: 99,
Visits: 242
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 output
rank 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)
Post #1350700
rhythmk
rhythmk
Posted Tuesday, August 28, 2012 1:09 AM
Old Hand
Group: General Forum Members
Last Login: Saturday, November 10, 2012 9:30 AM
Points: 388,
Visits: 603
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 output
rank 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/
Post #1350709
raghuldrag
raghuldrag
Posted Tuesday, August 28, 2012 1:25 AM
SSC Journeyman
Group: General Forum Members
Last Login: Today @ 6:24 AM
Points: 99,
Visits: 242
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
Post #1350710
ChrisM@Work
ChrisM@Work
Posted Tuesday, August 28, 2012 3:52 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 5,618,
Visits: 10,990
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
Post #1350775
ChrisM@Work
ChrisM@Work
Posted Tuesday, August 28, 2012 4:03 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 5,618,
Visits: 10,990
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
Post #1350777
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.