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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Horizontal display of column results

Author  Topic 

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-20 : 16:55:21
My table contains a client id and a type field that can contain various values. Is there a way to span the values in the type field horizontally, instead of vertically ?

select select clientid,typeid from mytable group by clientid,calltypeid order by clientid
results in this:

client**type
--------------
10.......A1
10.......A2


I'd like to have it like this:

Client**type1*type2
-----------------------
10.........A1.....A2


robert

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-07-20 : 18:43:02
if you get results like this

client type
10 A1,A2,A3

will it solve your purpose?



mk_garg
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-21 : 01:44:03
If possible do this in your presentation layer

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 08:17:36
quote:
Originally posted by mk_garg20

if you get results like this

client type
10 A1,A2,A3

will it solve your purpose?



mk_garg



Yes, that would work, so it would be like
10 A1,A2,A3
20 B5,B7,B9
30 etc....

It would be nice if the comma could be left out.

I hope it is possible.

Thanks

robert
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 08:22:10
quote:
Originally posted by madhivanan

If possible do this in your presentation layer

Madhivanan

Failing to plan is Planning to fail



Could you give a small example of how that would work ?

Thank you.

robert
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-21 : 08:36:41
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 09:42:16
I tried that, it's a nice method, but it is way too slow. I also realize that I have given incorrect explanation.

I need this :

clientid.......type1......type2......type3
10 120 500 33
20 18 20 37

So the cells are the sum per type per client.




robert
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-21 : 09:46:17
Then refer the Crosstab articles here
http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-07-21 : 09:57:40
how are you presenting this information? Using what client application?

- Jeff
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 10:02:26
quote:
Originally posted by jsmith8858

how are you presenting this information? Using what client application?

- Jeff



I'm gonna use it in crystal reports, I would like to use a stored procedure. But still I would just like to see it in the sql query output window.

robert
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 10:27:16
I found a link on your page referring to a crosstab, http://www.sqlteam.com/item.asp?ItemID=2955.

Exactly what I needed, and it's fast too!.

Thanks

robert
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-07-21 : 10:45:28
How many types are possible? How do you decide which is "type 1" versus "type 2" and so on?

The easiest way to do this to let SQL return the raw data in the its standard row/column format and then let Crystal do all formatting.

For example, on your crystal report you might:

1) create a group for "Client"
2) Determine how many columns you can possibly have (this must be fixed, of course, since you are formatting for a page). Call this "n"
3) Create a formula that executes for each row in the detail section and assigns the current Type to Type1, Type2, ... TypeN shared variables (or perhaps an array?).
4) Display the contents of the Type1, Type2, ... TypeN variables in different text boxes at the client footer.
5) Suppress the detail section and also the client header section. (since you only want 1 line per client). So you'd only display the fully formed client footer.

You must have some knowledge of crystal reports formulas and using shared variables and such, but it is pretty easy to do once you mess around with it. And it will be much more efficient than forcing SQL Server to do the work.


- Jeff
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-07-21 : 10:46:38
Update -- if you just need a standard cross tab (and not assining Type1, Type2, .. etc... ) then Crystal has this feature built-in. You don't need to do anything in SQL. Just add a cross tab to your report, assign the columns, and off you go.

- Jeff
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2005-07-21 : 11:31:15
Thanks a lot for the input. I'll give it a shot just using crystal.


robert
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-07-21 : 18:39:18
it will work in crystal reports.

cheers


mk_garg
Go to Top of Page
   

- Advertisement -