0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by shifa888
0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

-1

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>

Edited by nav33n: Please use [code] tags to wrap your code for easy readability.

Votes + Comments
not even tsql...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.