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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select INTO error

Author  Topic 

nguyenl
Posting Yak Master

128 Posts

Posted - 2008-07-31 : 14:42:19
Hi,

My Select INTO is not working properly. Keeps saying bad syntax. Not sure why. Please help.

Thanks,

-Long


CREATE PROCEDURE [dbo].[getbldg_x](@propid INTEGER,
@taxyear INTEGER)


AS

BEGIN




declare @aBldg varchar(3)
declare @aRecid iNT
declare @aYrBlt varCHAR(4)
declare @aSqft INT
declare @wrkA1 INT
declare @wrkA2 INT
declare @wrkA3 INT
declare @wrkA4 INT
declare @wrkA5 INT
declare @aCode varCHAR(18)
declare @aQuality varCHAR(2)
declare @aCondition varCHAR(2)
declare @aNumSt INT
declare @aPctGood INT
declare @tmpCode varCHAR(4)

Select
'RES'
--recid1
--year_built,
--main_fn_area,
--uppr_fn_area,
--unfin_area,
--bsmt_area,
--bldg_style,
--quality,
--condition,
--num_stories,
--phy_pct_good
INTO
@aBldg
--@aRecid
--@aYrBlt,
--@wrkA1,
--@wrkA2,
--@wrkA3,
--@wrkA4,
--@tmpCode,
--@aQuality,
--@aCondition,
--@aNumSt,
--@aPctGood
FROM
residence,
parcel
WHERE parcel.property_id = @propid
and parcel.parcel_year = @taxyear
-- AND parcel.parcel_year > 0 and parcel.parcel_year < 3000
AND parcel.link_id = residence.link_id

end

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-31 : 14:44:09
You can't SELECT INTO a table variable. Use a # temp table instead.

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

Subscribe to my blog
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-31 : 15:09:40
If you are trying to assign columns from a select to variables, you can use SELECT like this:

select @var1 = table.col1, @var2 = table.col2
from table

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -