How to store all rows of a column in a sql variable
-
Hi All, I have A Table, which contains 40000 records. I want to store values of all rows of a column in a sql variable. the column daytatpe is Varbinary. there is ID column also. I need to append these records order by ID (ASC) when I appent rows in a variable. I did something like this:- Table Schema is Create table TempTable ( ID Identity int, ColData varbinary(max) Colchange varbinary(max) ) DECLARE @ActData varbinary(max) DECLARE @ActChainage varbinary(max) SET @ActData = cast('' as varbinary) SET @ActChainage = cast('' as varbinary) SELECT @ActData = @ActData + ColData , @ActChainage = @ActChainage + Colchange from TempTable Order by Id select cast(@ActChainage as varchar(max)) When I use "Order by ID" then query return only last record, but without using "Order By ID" it returns all records in a sql variable, but not in sort order. I need Order by ID. Can any help me out to solve this problem? Regards, Rajesh
rajesh
-
Hi All, I have A Table, which contains 40000 records. I want to store values of all rows of a column in a sql variable. the column daytatpe is Varbinary. there is ID column also. I need to append these records order by ID (ASC) when I appent rows in a variable. I did something like this:- Table Schema is Create table TempTable ( ID Identity int, ColData varbinary(max) Colchange varbinary(max) ) DECLARE @ActData varbinary(max) DECLARE @ActChainage varbinary(max) SET @ActData = cast('' as varbinary) SET @ActChainage = cast('' as varbinary) SELECT @ActData = @ActData + ColData , @ActChainage = @ActChainage + Colchange from TempTable Order by Id select cast(@ActChainage as varchar(max)) When I use "Order by ID" then query return only last record, but without using "Order By ID" it returns all records in a sql variable, but not in sort order. I need Order by ID. Can any help me out to solve this problem? Regards, Rajesh
rajesh