Query for displaying a particular set of data | Member | | Join Date: Jul 2008
Posts: 42
| | |
Hi,
I have a table with fields number,category,date and if i want to choose numbers of a particular category and date.
then the query will b
select number from <table name> where category=" " and date =" "
and it will display a list of numbers.
And wat if i want those numbers horizontally.Suppose i hav three numbers
123
234
678
and i want it to be like this
123 234 678
but it should be done automatically. is there any query for that.
|  | Familiar Sight | | Join Date: Mar 2007 Location: India
Posts: 221
| | | re: Query for displaying a particular set of data
Try this, and reply me - DECLARE @numberList varchar(255)
-
Select @numberList = IsNull(number + ',' + @numberList, NULLIF( number, @numberList)) from <tablename> where <condition>
-
Select @numberList as numberList
|  | Expert | | Join Date: Jun 2007
Posts: 1,925
| | | re: Query for displaying a particular set of data
If this is a big data and you're using sql2005, use UN/PIVOT...
-- CK
| | Member | | Join Date: Jul 2008
Posts: 42
| | | re: Query for displaying a particular set of data
Thanks a lot.It works.
And wat if I want to select number and category where date is given like
number category date
123 1 8/12/2008
234 1 8/12/2008
123 2 8/12/2008
789 2 8/12/2008
5678 1 8/12/2008
then i should get:
numberlist category
123,234,5678 1
123,789 2
can u plz help me in this.
| | Member | | Join Date: Jul 2008
Posts: 42
| | | re: Query for displaying a particular set of data Quote:
Originally Posted by rsrinivasan Try this, and reply me - DECLARE @numberList varchar(255)
-
Select @numberList = IsNull(number + ',' + @numberList, NULLIF( number, @numberList)) from <tablename> where <condition>
-
Select @numberList as numberList
Thanks a lot.Ur query helps me a lot
i want to store the data from variable to a new table.can it b possible.plz reply
| | Member | | Join Date: Jul 2008
Posts: 42
| | | re: Query for displaying a particular set of data Quote:
Originally Posted by rsrinivasan Try this, and reply me - DECLARE @numberList varchar(255)
-
Select @numberList = IsNull(number + ',' + @numberList, NULLIF( number, @numberList)) from <tablename> where <condition>
-
Select @numberList as numberList
Hi,
I want the variable data in a new table.cud u plz help me.
|  | Expert | | Join Date: Jun 2007
Posts: 1,925
| | | re: Query for displaying a particular set of data
You can parse the variable.
But I'd still say you use PIVOT/UNIPVOT, if you're running sql 2005.
-- CK
| | Member | | Join Date: Jul 2008
Posts: 42
| | | re: Query for displaying a particular set of data Quote:
Originally Posted by ck9663 You can parse the variable.
But I'd still say you use PIVOT/UNIPVOT, if you're running sql 2005.
-- CK would u plz help me in that?
|  | Moderator | | Join Date: Mar 2007 Location: Hyderabad, India
Posts: 2,192
| | | re: Query for displaying a particular set of data | | Member | | Join Date: Jul 2008
Posts: 42
| | | re: Query for displaying a particular set of data Quote:
Originally Posted by amitpatel66 PIVOT for MSSQL 2005
i dont know how to use PIVOT. I have only one table.i have to concatenate the multiple records into single record.
Can u send me a query related to my prob.
|  | Similar Microsoft SQL Server bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|