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)
 Error while declare the variable in stored procedu

Author  Topic 

kamal.A
Yak Posting Veteran

70 Posts

Posted - 2008-09-01 : 13:59:05
Hi All,

I write a stored procedure below is it correct?

CREATE PROCEDURE temp

As

DECLARE @CompanyId AS BigInt

@CompanyId = SELECT LNCN_ParentId FROM Contact WHERE ContactId = 12

INSERT INTO tempTbl(CompanyId) VALUES(@CompanyId)

END

I got the below error,.

correct syntax near '@CompanyId'.
Must declare the variable '@CompanyId'.


Kindly help me...

Kamal...




jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-09-01 : 15:42:10
change this:

@CompanyId = SELECT LNCN_ParentId FROM Contact WHERE ContactId = 12

to this:

SELECT @CompanyId=LNCN_ParentId FROM Contact WHERE ContactId = 12


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-02 : 02:50:03
or

CREATE PROCEDURE temp
As
INSERT INTO tempTbl(CompanyId)
SELECT LNCN_ParentId FROM Contact WHERE ContactId = 12


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -