Solved

Storing variable itnto declared variable in stored procedure

Posted on 2008-06-26
3
1,653 Views
Last Modified: 2010-04-21
Hi,

I wat to create stored procedure in sql server 2005.
1) i want to retirve data from table1 and assign to variable which would have declared in stored procdeure. Later i will be using this variable in stored procedure.
i..,
Create   PROCEDURE [dbo].[sp1]  
BEGIN  
  Declare @NewEventCode   varchar(20)
//i want to retreive data rom table1( which will have only one record and one column ) and assign the value to @NewEventCode  .
like ..
"select  code1  to @NewEventCode   from table1 "



Can you please help us on this.
thanks,
Ram


0
Comment
Question by:ram27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 125 total points
ID: 21878048
declare @neweventcode int

select @neweventcode = code1 from table1
0
 

Author Closing Comment

by:ram27
ID: 31471132
Thanks a lot
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 21878310
To achieve what you want you need to use the following SQL Query

Declare @NewEventCode   varchar(20)

Select @NewEventCode = table1.EventCode
  From table1
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question