There is a query as following.....
-Creat a test table
if object_id('tbTest') is not null
drop table tbTest
GO
create table tbTest(m_date int, m_name varchar(10),m_hour int)
insert tbTest
select 1991,'Jack',1 union all
select 1991,'Jack',1 union all
select 1991,'Tom',1 union all
select 1992,'Jack',1 union all
select 1992,'Bob',1
-create the query
declare @.sql varchar(8000)
set @.sql = 'select '
select @.sql = @.sql + ',' + m_name + '=sum(case m_name when ''' + m_name + ''' then m_hour else 0 end)'
from tbTest group by m_name
EXEC(@.sql + ' from tbTest group by m_date')
the result run on MS sql server
/*result
m_date Bob Tom Jack
-- -- -- --
1991 0 1 2
1992 1 0 1
*/
But the result in Sybase is
m_date Bob
-- --
1991 0
1992 1
Why?How to modify the query to get the same result just as it on MS sql server.
You might posting this in a Sysbase related forum.
No comments:
Post a Comment