Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable not declare.....

Status
Not open for further replies.

cwal

Programmer
Joined
Jun 12, 2002
Messages
4
Location
BR
Hello. I'm trying to use a variable to identify a table(nomtable), but it doesn't work. The message of error is that:
error 170 - must declare the variable @nomtab

The text is below, if you want to check.
I thank a lot for your help



create procedure SomaURL @dia varchar(2), @mes varchar(2), @ano varchar(2)
as
begin
declare @nomtab varchar(8),
@campotab varchar(5)

set @campotab = cast('dia' as varchar(3)) + ' ' + @dia
set @nomtab = cast( 'mes' as varchar(3)) + ' ' + @mes +' ' + cast( '/' as varchar(1)) + ' ' + @ano


-- confere se a tabela do mes existe senao cria a tabela
if not exists (select * from dbo.sysobjects where name=@nomtab and xtype='U' )
begin
CREATE TABLE @nomtab(
[char] (70) COLLATE SQL_Latin1_Gen...B where @nomtab.URL = B.URL) end
 
Hi,

try this SP

create procedure SomaURL @dia varchar(2), @mes varchar(2), @ano varchar(2)
as

declare @nomtab varchar(8),
@campotab varchar(5),
@Sel varchar(500)
set @campotab = cast('dia' as varchar(3)) + ' ' + @dia
set @nomtab = cast( 'mes' as varchar(3)) + ' ' + @mes +' ' + cast( '/' as varchar(1)) + ' ' + @ano


-- confere se a tabela do mes existe senao cria a tabela
if not exists (select * from dbo.sysobjects where name= @nomtab and xtype='U' )
begin
Set @sel = 'CREATE TABLE' + @nomtab + '( [char] (70) COLLATE SQL_Latin1_Gen...ere @nomtab.URL = B.URL)' exec(@sel) Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top