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 |
cheatasp
Starting Member
10 Posts |
Posted - 2009-05-21 : 23:39:36
|
Dear All,I have open problem with querySELECT '*' + REPLACE(AssetCode,'-','') + '*' FROM TAB_Assetit will return 1 column and 3 rows, but I want to show 3 columns and 1 row.Please help me.Thanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-22 : 04:16:52
|
so you want cross tabbed result? can you illustrate what all values you want to cross tab with an example? |
|
|
cheatasp
Starting Member
10 Posts |
Posted - 2009-05-22 : 04:39:51
|
DearNow I got my result already, I use temp table like thisCREATE TABLE TPR_Temp( Ass_ID int, AssetCode1 nvarchar(16) NULL, AssetCode2 nvarchar(16) NULL, AssetCode3 nvarchar(16)NULL,) Declare @AssetCode nvarchar(16)Declare @i intDeclare @id intset @id=1set @i=0Declare c cursor for sELECT '*' + replace(AssetCode,'-','')+'*' FROM TAB_Assetopen cfetch c into @AssetCodewhile(@@FETCH_STATUS=0)begin if(@i=0) begin insert into tpr_temp(Ass_ID,AssetCode1) values(@id,@AssetCode) end else if(@i=1) begin update tpr_temp set AssetCode2=@AssetCode where Ass_ID=@id end else if(@i=2) begin update tpr_temp set AssetCode3=@AssetCode where Ass_ID=@id set @id=@id+1 set @i=-1 end set @i=@i+1print @AssetCode fetch c into @AssetCode endDeallocate cclose cSelect * from TPR_TempDrop TABLE TPR_TempThanks |
|
|
|
|
|
|
|