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