Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Temp table in stored procedure is not getting filled up

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 24 Jul 2008 21:41 GMT
Hi I have a view as the following: This view has SalesPerson as a alias name.
(PROJ.Last_Name + ' ' + PROJ.First_Name AS SalesPerson)

Now I need to test a prototype procedure and then extend the concept to the
real one.

I am trying to create a temptable that will have the projectno and
salesperson information from the estimate3 (after a groupby) However when I
am running this it is not inserting any record in the temptable. When I do a
simple select statement
as follows I get close to 1100 records. I am not sure why the temp table is
not getting filled up with the salesperson data. Any help is appreicated.
Thanks

select projectno, salesperson
from estimate3
group by projectno, salesperson

CODE FOR VIEW

CREATE VIEW dbo.Estimate3
AS
SELECT     EST.ProjectNo + '-' + EST.EstimateNo AS FullEstimateNo, EST.*,
dbo.Plant.Plant_Desc AS PlantName, PROJ.Project_Name AS Project_Name,
                     ENG.Name AS EngineerName, dbo.tblMaterial.FamilyCode
AS FamilyCode, dbo.tblEstimateMaterial.QtyPer AS QtyPer,
                     dbo.tblEstimateMaterialCost.QuoteUnitCost AS
QuoteUnitCost, PROJ.YearlyQty, PROJ.aQty, PROJ.annVol1, PROJ.accManager,
                     PROJ.Last_Name + ' ' + PROJ.First_Name AS SalesPerson
FROM         dbo.Plant RIGHT OUTER JOIN
                     dbo.estimate_tr EST INNER JOIN
                     dbo.tblMaterial INNER JOIN
                     dbo.tblEstimateMaterial ON dbo.tblMaterial.MaterialKey
= dbo.tblEstimateMaterial.MaterialKey ON
                     EST.EstimateKey = dbo.tblEstimateMaterial.EstimateKey
INNER JOIN
                     dbo.tblEstimateMaterialCost ON
dbo.tblEstimateMaterial.EstimateMaterialKey =
dbo.tblEstimateMaterialCost.EstimateMaterialKey LEFT OUTER JOIN
                     dbo.Project2 PROJ ON PROJ.ProjectNo = EST.ProjectNo ON
dbo.Plant.Plant = EST.Plant LEFT OUTER JOIN
                     dbo.Engineer ENG ON EST.Engineer = ENG.User_ID

CODE FOR STORED PROCEDURE

alter proc sp_checking_salesperson
 @family_code varchar(50)
As
create table #temptest(
projectno varchar(50),
salesperson varchar(100)
)

select projectno, salesperson
into #temptesting
from estimate3
group by projectno, salesperson

select * from #temptest
Aaron Bertrand [SQL Server MVP] - 24 Jul 2008 21:45 GMT
> alter proc sp_checking_salesperson
>   @family_code varchar(50)
[quoted text clipped - 10 lines]
>
> select * from #temptest

All you've done is created a table and run two selects.  Data can only get
into #temptest if you actually run an insert statement.  And you probably
want to make sure you either use #temptest or #temptesting, but not both.
For that matter, why not come up with a meaningful name now, instead of
either changing it when you're no longer temp/testing, or leaving it that
way?

INSERT INTO  #temptest
SELECT ...
Jack - 24 Jul 2008 21:58 GMT
Thanks for pointing out the mistake along with the other pice of advice. I
appreciate it Aaron.

> > alter proc sp_checking_salesperson
> >   @family_code varchar(50)
[quoted text clipped - 20 lines]
> INSERT INTO  #temptest
> SELECT ...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.