Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to store all rows of a column in a sql variable

How to store all rows of a column in a sql variable

Scheduled Pinned Locked Moved Database
databasehelpxmltutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajesh_K_Sharma
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • R Rajesh_K_Sharma

      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

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Why you don't use temporary table instead of sql variable?


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups