Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert into a temp table

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2008-10-10 : 15:49:08
Set @SQL='EXEC Usp_Activities_All_Listing ''SELECT ALL ACTIVITIES'',0,0,0';
--Select * from #TempActivities
If exists(select * from #TempActivities)
delete from #TempActivities;

Insert Into #TempActivities Exec(@SQL);

I am using the above as part of a procedure.

When I step through the code immediately at the insert I get a message that ArticleID column name is invalid.
I am creating this temp table before this.
I have the same table structure defined for the temp table as that of the result coming from Exec(@SQL)

What could be wrong here.
Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-10 : 15:54:45
You haven't provided enough information for us to help. At a minimum, provide the entire error message, the DDL of #TempActivities, and a sample row from EXEC(@sql).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

BendJoe
Posting Yak Master

128 Posts

Posted - 2008-10-10 : 16:04:41
quote:
Originally posted by tkizer

You haven't provided enough information for us to help. At a minimum, provide the entire error message, the DDL of #TempActivities, and a sample row from EXEC(@sql).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Running [dbo].[Usp_SearchByAll_Management] ( @Operation = Activities, @Keywords = rosh, @WithAllWords = , @ExactPhrase = , @Username = , @SpecificSavvyContent = , @UserID = 0 ).

Invalid column name 'ArticleID'.
Column1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Select * from #TempActivities Where ArticleTitle Like '%rosh%' OR ArticleContent Like '%rosh%'
(1364 row(s) affected)
(1 row(s) returned)
GroupID ArticleID GroupTitle GroupImage ArticleTitle ArticleContent DateAdded ActiveDate ArticleImage Rating ViewCount
----------- ----------- -------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- ----------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------- -----------
(1364 row(s) affected)
(0 row(s) returned)
@RETURN_VALUE = 0
Finished running [dbo].[Usp_SearchByAll_Management].
The thread (0x778) has exited with code 0 (0x0).
The program '[1268] [SQL] has exited with code 0 (0x0).

DDL looks like this.
Convert(int,G.GroupID) as GroupID,
Convert(int,A.ArticleID)as ArticleID,
G.Title GroupTitle,
Cast(NULL AS VARCHAR(1024)) GroupImage,
A.Title ArticleTitle,
A.ArticleContent ArticleContent,
A.DateAdded DateAdded,
A.ActiveDate ActiveDate,
Cast(NULL AS VARCHAR(1024)) ArticleImage,
0 Rating,
0 ViewCount
INTO
#TempActivities
FROM
Groups G,
ArticleGroupLink AG,
GroupCategory GC,
Articles A
WHERE

G.GroupCategoryID = GC.GroupCategoryID AND

AG.GroupID = G.GroupID AND
A.ArticleID = AG.ArticleID
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-11 : 01:08:05
It seems like ArticleID column used inside procedure does not exists in the specified table. Could you please specified tables (ArticleGroupLink & Articles) to check if column really exists
Go to Top of Page
   

- Advertisement -