Solved

Storing variable itnto declared variable in stored procedure

Posted on 2008-06-26
3
1,648 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
3 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 125 total points
Comment Utility
declare @neweventcode int

select @neweventcode = code1 from table1
0
 

Author Closing Comment

by:ram27
Comment Utility
Thanks a lot
0
 
LVL 18

Expert Comment

by:Richard Lee
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now