Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable

Status
Not open for further replies.

sardinka2

Programmer
Joined
May 6, 2004
Messages
38
Location
US
I have a param @MessageBody varchar(8000).
I am assigning some values to the select @MessageBody=select.... It working fine until I the results is only 1 row, however when it is more then one it is taking only top 1 row. What should I do in order to get all rows?
 
I'm not exactly sure what you want to do with the variable @MessageBody but the code below will print out the results of the query. You'll basically have to load the query results into a cursor and add them to the variable. If you lets us know what your going to do with the variable @MessageBody we may be able to help out more.

<code>
declare @MessageBody varchar(8000)
declare @DataHolder varchar(50)
set @MessageBody = 'Query Results'

declare data_cursor cursor for
select something
from tablename

open data_cursor

fetch next from data_cursor
into @DataHolder
while @@FETCH_STATUS = 0
begin
select @MessageBody = @MessageBody + CHAR(13) + CHAR(10) + @DataHolder
fetch next from data_cursor
into @DataHolder
end
close data_cursor
deallocate data_cursor

print (@MessageBody)
</code>
 
YOu can only have one value ina parameter defined as varchar. If you need multiple values you need a table variable.

POst your code if you want help on a problem like this.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top