Skip to content
Advertisement

script issue Transact-SQL

I Want to return All table names from a use data base but this just return a char

declare @contador int

set @contador = 1

while (@contador<=(select count(table_name) from INFORMATION_SCHEMA.TABLES))
begin
declare @tableName varchar
    set @tableName =  (select top 1 * from (select top(@contador) table_name from INFORMATION_SCHEMA.TABLES order by table_name asc) as nombre order by table_name desc)
    print @tableName
    set @contador = @contador + 1
end

the output is s s s s s s

Advertisement

Answer

declare @tableName varchar(100)

You need to define the length of @tableName, by default it is set to 1 character.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement