November 22, 2009 at 8:47 pm
Hi,
Steps in my sp goes like this:-
declare @mytable table (a int, b int, c int);
insert into @mytable select tablename.field1, tablename.field2, tablename.field3;
declare @newtable table (d int, e int, fint);
insert into @newtable select @mytable.a, @mytable.b, @mytable.c;
in the last line, i get an error message that " must declare scalar variable @mytable".
What do I do?
Thanks.
Sanya
November 22, 2009 at 9:27 pm
sanya.ibrahim (11/22/2009)
declare @mytable table (a int, b int, c int);insert into @mytable select tablename.field1, tablename.field2, tablename.field3;
You don't have from clause in the above statement how will it work?
You need to change the query
Insert into @mytable select field1, field2, field3 from tablename
declare @newtable table (d int, e int, fint);
insert into @newtable select @mytable.a, @mytable.b, @mytable.c;
You need to change the query
Insert into @newtable select a, b, c from @mytable
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 23, 2009 at 7:04 am
Also, you cannot use a table variable name as a qualifier. You must alias the table variable as shown below. This will become important when you use table variables joined to other tables.
declare @sample Table (ID int identity(1,1) primary key, Name varchar(50))
insert into @sample
select 'Adam' union all
select 'Brad' union all
select 'Carla'
select S.ID, S.Name from @sample S -- you can't use @sample.ID and @sample.Name
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
November 23, 2009 at 8:31 am
Bru Medishetty (11/22/2009)
sanya.ibrahim (11/22/2009)
declare @mytable table (a int, b int, c int);insert into @mytable select tablename.field1, tablename.field2, tablename.field3;
You don't have from clause in the above statement how will it work?
You need to change the query
Insert into @mytable select field1, field2, field3 from tablename
declare @newtable table (d int, e int, fint);
insert into @newtable select @mytable.a, @mytable.b, @mytable.c;
You need to change the query
Insert into @newtable select a, b, c from @mytable
Sorry, I forgot to write the "from" clause in the code I wrote here in the forum. The actual sp has the 'from' clause.
November 23, 2009 at 8:34 am
sanya.ibrahim (11/23/2009)
Sorry, I forgot to write the "from" clause in the code I wrote here in the forum. The actual sp has the 'from' clause.
Then post the actual sp.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 23, 2009 at 8:55 am
GilaMonster (11/23/2009)
sanya.ibrahim (11/23/2009)
Sorry, I forgot to write the "from" clause in the code I wrote here in the forum. The actual sp has the 'from' clause.Then post the actual sp.
Best possible suggestion !
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 23, 2009 at 9:36 am
Sorry guys for all the trouble, but the suggestion by SSCrazy resolved the issue.
Thanks a lot SSCrazy and all others
November 23, 2009 at 9:41 am
sanya.ibrahim (11/23/2009)
Sorry guys for all the trouble, but the suggestion by SSCrazy resolved the issue.Thanks a lot SSCrazy and all others
One more suggestion..
Bob Hovious 24601 is the user not SSCCrazy
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
November 24, 2009 at 9:41 am
So sorry......
(: OK, you guys can have one more beer on me.....
and thanks once again
November 24, 2009 at 10:09 am
You're welcome... and don't worry.
I've been called lots worse things than SSC Crazy.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy