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.
Author |
Topic |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2006-07-24 : 23:42:23
|
hiI can't get this to work.Drop Table #Mytablecreate table #Mytable (TCode varchar(10), TransDa int, Amount int, LedType Varchar(15))insert #Mytableselect '01', 2006001, 1000, 'Acutal' union allselect 'AB001', 2006001, 1100, 'Forecast' union allselect 'AB002', 2006001, 1020, 'Forecast' union allselect '02', 2006001, 1150, 'Acutal' union allselect 'AB001', 2006002, 1200, 'Forecast' union allselect 'AB001', 2006002, 1210, 'Forecast' union allselect 'AB003', 2006003, 1110, 'Forecast' union allselect 'con', 2006002, 2000, 'Acutal'----------------------------------------------------------------------------------------declare @s varchar(300)declare @s1 varchar(300)Set @s = ''Set @s1 = ''If Len(@s + ' case when TCode Like ''' + TCode + ''' and TransDa = ' + cast(TransDa as varchar(10)) + ' and LedType = ''Forecast''' + ' then Amount else 0 end as [' + TCode + '-' + cast(TransDa as varchar(15)) + ']') > 300BeginSelect @s1 = isnull(@s1 + ',' + char(13), '') + ' case when TCode Like ''' + TCode + ''' and TransDa = ' + cast(TransDa as varchar(10)) + ' and LedType = ''Forecast''' + ' then Amount else 0 end as [' + TCode + '-' + cast(TransDa as varchar(15)) + ']'from #Mytable where TCode like 'AB%' group by TCode, TransDaendelseBeginselect @s = isnull(@s + ',' + char(13), '') + ' case when TCode Like ''' + TCode + ''' and TransDa = ' + cast(TransDa as varchar(10)) + ' and LedType = ''Forecast''' + ' then Amount else 0 end as [' + TCode + '-' + cast(TransDa as varchar(15)) + ']'from #Mytable where TCode like 'AB%' group by TCode, TransDaendexec('select *,' + @s + ' ' + @s1 + ' from #Mytable order by TCode, TransDa')------------------------------------------------------------I have gone thru the link http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=52274Any help thank. |
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2006-07-25 : 00:13:25
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69553Damian"A foolish consistency is the hobgoblin of little minds." - Emerson |
|
|
|
|
|
|
|