Solved

Storing variable itnto declared variable in stored procedure

Posted on 2008-06-26
3
1,651 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
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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