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
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