gudidi
asked on
cross tab sql query
Hi Experts
is there any simple query to make a cross tab?
my data looks like this:
id name
1 gidi1
1 gidi2
1 gidi3
2 gidi4
2 gidi5
and i want it to look like that:
id name1 name2 name3
1 gidi1 gidi2 gidi3
2 gidi4 gidi5
10x a lot
is there any simple query to make a cross tab?
my data looks like this:
id name
1 gidi1
1 gidi2
1 gidi3
2 gidi4
2 gidi5
and i want it to look like that:
id name1 name2 name3
1 gidi1 gidi2 gidi3
2 gidi4 gidi5
10x a lot
ASKER
hi
the main problem is that i cannot use aggregate function for varchar column.
how do i solve this problem?
the main problem is that i cannot use aggregate function for varchar column.
how do i solve this problem?
you can use it... try to use it, it will work
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i will check it and let you know
changes for above function with your desired table (i avoided the cursors as it kills time) :
line 16 :replace your column id
line 17 : replace your table
line 27 : don't replace "e" -that is table alias name ..you can replace name with your coulmn name
line 28 : replace your column name
line 29 : replace your table name
that's it.. create function and use select query from code snippet
in the code ,replace your cloumn names and tables
line 16 :replace your column id
line 17 : replace your table
line 27 : don't replace "e" -that is table alias name ..you can replace name with your coulmn name
line 28 : replace your column name
line 29 : replace your table name
that's it.. create function and use select query from code snippet
in the code ,replace your cloumn names and tables
select distinct id,[dbo].[Concat_name] (id) from [dbo].[tbSample]
group by id ,name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.sqlhub.com/2009/05/dynamic-pivot-with-month-number-to.html
http://www.sqlhub.com/2009
http://www.sqlhub.com/2009
http://www.sqlhub.com/2009
http://www.sqlhub.com/2009