Hello,

I am trying to make this code to combine the varchar string using fetch technique.
The purpose for the code below is to combine all of the results and display back as 1 record instead of multiple records.

We have SQL 2000 server.

Thanks guys

CREATE PROCEDURE get_all_clumns_name
(
@table_name  varchar(200)
)

AS
declare @current int
declare @columns_names_holder varchar(500)
declare @columns_names varchar(200)
set @current=0
DECLARE authors_cursor CURSOR FOR
select  top 5 col.name   from sysobjects obj inner join syscolumns col on obj.id = col.id where obj.name = @table_name ORDER BY col.name

OPEN authors_cursor
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns

--http://msdn.microsoft.com/en-us/library/aa258896(SQL.80).aspx
FETCH NEXT FROM authors_cursor INTO @columns_names

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.

WHILE @@FETCH_STATUS = 0

BEGIN
set @current=@current+1
   -- This is executed as long as the previous fetch succeeds.
set @columns_names_holder=@columns_names_holder+CONVERT(varchar(200), @columns_names_holder)
   FETCH NEXT FROM authors_cursor   INTO @columns_names

END

CLOSE authors_cursor
DEALLOCATE authors_cursor

--output back the result
select all_columns= @columns_names_holder
GO

I have an answer.
If you anyone want to see please look the the below.

Thanks.

declare @Table_name varchar(100) = 'xyz'
DECLARE @Columns  varchar(8000)
select top 5 @Columns = COALESCE (@Columns+' ', '') +col.name
from sysobjects obj
inner join syscolumns col on obj.id = col.id where obj.name = @table_name ORDER BY col.name
SELECT @Columns

I tried this and had it echo back the $var. The echo came back, literally, as the word " Array ".

This is what I did --

$var = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$var[ ] = $row;
}
echo "$var".

Please help.

Edited 1 time(s). Last edit was ten months ago by RiceDaddy7.
______________________________
<snip>
<snip>

commented: not even tsql... -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.