Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 405
BlaShadow Avatar asked Apr 20 '12 13:04

BlaShadow


People also ask

What is T-SQL scripting?

T-SQL (Transact-SQL) is a set of programming extensions from Sybase and Microsoft that add several features to the Structured Query Language (SQL), including transaction control, exception and error handling, row processing and declared variables.

What is the use of @@ error in SQL Server?

Using @@ERROR to conditionally exit a procedure. The following example uses IF...ELSE statements to test @@ERROR after an DELETE statement in a stored procedure. The value of the @@ERROR variable determines the return code sent to the calling program, indicating success or failure of the procedure.


2 Answers

declare @tableName varchar(100)

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

like image 55
Darren Avatar answered Sep 24 '22 18:09

Darren


try declare @tableName varchar(100)

like image 21
JBrooks Avatar answered Sep 23 '22 18:09

JBrooks