| Author |
Topic |
|
rauk10
Starting Member
16 Posts |
Posted - 2008-08-10 : 12:43:48
|
| I have one problem regarding grouping.I have a table like thisID NAME LOCATION1 Abc TX2 cde TX3 Fgh TX4 Ijk NY5 Mno NY6 Def NY7 ghi CAI want to group them by the Location asNAME LOCATIONAbc TXcde TXFgh TXNAME LOCATIONIjk NYMno NYDef NYNAME LOCATIONghi CAI would really appreciate your help.Thank You. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-10 : 13:17:54
|
| you want to break them to show in three resultsets? |
 |
|
|
rauk10
Starting Member
16 Posts |
Posted - 2008-08-10 : 13:21:52
|
quote: Originally posted by visakh16 you want to break them to show in three resultsets?
Yes I want to break them. I want them to be group by the location. So here I want to break it in three recordsetsI would really appreciate that. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-10 : 13:28:24
|
| You'll need to run three different queries then. You can wrap it into a stored procedure though, so you only need to run one thing.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-10 : 13:29:35
|
quote: Originally posted by rauk10
quote: Originally posted by visakh16 you want to break them to show in three resultsets?
Yes I want to break them. I want them to be group by the location. So here I want to break it in three recordsetsI would really appreciate that.
cant you make a procedure with a parameter for location and execute it with a location value to return only values belonging to location? |
 |
|
|
rauk10
Starting Member
16 Posts |
Posted - 2008-08-10 : 13:40:25
|
quote: Originally posted by visakh16
quote: Originally posted by rauk10
quote: Originally posted by visakh16 you want to break them to show in three resultsets?
Yes I want to break them. I want them to be group by the location. So here I want to break it in three recordsetsI would really appreciate that.
cant you make a procedure with a parameter for location and execute it with a location value to return only values belonging to location?
can you tell me how can I do that |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-10 : 13:46:27
|
| [code]CREATE PROC GetLocationData@Location varchar(100)ASSELECT NAME,LOCATIONFROM YourTableWHERE LOCATION=@LocationORDER BY IDGO[/code]execute it like this[code]EXEC GetLocationData 'TX'--1st resultsetEXEC GetLocationData 'NY'--2nd resultsetEXEC GetLocationData 'CA'--3rd resultset[/code] |
 |
|
|
rauk10
Starting Member
16 Posts |
Posted - 2008-08-10 : 13:58:15
|
quote: Originally posted by visakh16
CREATE PROC GetLocationData@Location varchar(100)ASSELECT NAME,LOCATIONFROM YourTableWHERE LOCATION=@LocationORDER BY IDGO execute it like thisEXEC GetLocationData 'TX'--1st resultsetEXEC GetLocationData 'NY'--2nd resultsetEXEC GetLocationData 'CA'--3rd resultset
Thank You very much. It really helped. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-10 : 14:03:03
|
quote: Originally posted by rauk10
quote: Originally posted by visakh16
CREATE PROC GetLocationData@Location varchar(100)ASSELECT NAME,LOCATIONFROM YourTableWHERE LOCATION=@LocationORDER BY IDGO execute it like thisEXEC GetLocationData 'TX'--1st resultsetEXEC GetLocationData 'NY'--2nd resultsetEXEC GetLocationData 'CA'--3rd resultset
Thank You very much. It really helped.
You're welcome . glad that i could help you out. Suggest you to learn about procedures by refering to books onlinehttp://msdn.microsoft.com/en-us/library/ms187926.aspx |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-11 : 03:27:33
|
quote: Originally posted by rauk10 I have one problem regarding grouping.I have a table like thisID NAME LOCATION1 Abc TX2 cde TX3 Fgh TX4 Ijk NY5 Mno NY6 Def NY7 ghi CAI want to group them by the Location asNAME LOCATIONAbc TXcde TXFgh TXNAME LOCATIONIjk NYMno NYDef NYNAME LOCATIONghi CAI would really appreciate your help.Thank You.
Where do you want to show data?If you use Reports, group it by LocationMadhivananFailing to plan is Planning to fail |
 |
|
|
|