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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in code 1

Status
Not open for further replies.

pauledward123

Technical User
Nov 15, 2011
2
Hello

Just starting with SQL and i'm experimenting with creating a temporary table and storing variables. I'm trying th efollowing code but I get an error "Invalid object name 'Temptable'."

Here's the code:
Code:
WITH Temptable AS
(
SELECT ID_prom, Name_prom 
FROM TSSITE_Prominences_prom
)

select top 1 ID_prom, Name_prom from Temptable 

declare @b int, @c varchar(20)
select 
@b = ID_prom, @c = Name_prom
from Temptable
 
Thanks a lot. Other thing I found is that a statement must be terminated with a ; before a common table expression

Code:
declare @b int, @c varchar(20);

WITH Temptable AS
(
SELECT ID_prom, Name_prom
FROM TSSITE_Prominences_prom
)

select
@b = ID_prom, @c = Name_prom
from Temptable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top