473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Stored Procedure Local Variables

86
Hello,

I'm relatively new to the world of Stored Procedures in SQL Server. This may be a silly question, but I've done some searching and haven't come up with any solid answers.

Is is possible to assign the result of a SELECT statement e.g.
Expand|Select|Wrap|Line Numbers
  1.  SELECT TOP 1 Cust_Name FROM Customers
to a local variable within my stored procedure? If so, is this a good practice, or is there a better approach?

Thank you.
Jun 11 '07 #1
3 2384
You can use them in ur stored procedures. It mainly depends on the requirements.

here is a sample procedure for ur question

CREATE PROCEDURE Top_Customer AS
begin

Declare

@l_top_customer varchar(100)


set @l_top_customer = (select top 1cust_name from Bharath_Practise.dbo.Cust_Record)

print @l_top_customer

END
GO
Jun 12 '07 #2
enreil
86
Thanks! This works nicely.

You can use them in ur stored procedures. It mainly depends on the requirements.

here is a sample procedure for ur question

CREATE PROCEDURE Top_Customer AS
begin

Declare

@l_top_customer varchar(100)


set @l_top_customer = (select top 1cust_name from Bharath_Practise.dbo.Cust_Record)

print @l_top_customer

END
GO
Jun 12 '07 #3
Motoma
3,237 Expert 2GB
Thanks for the great response BHARATH RS. Glad to have you around.
Jun 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
7
by: Alex | last post by:
Hi all, I am trying to install a java stored procedure via the windows development centre. The linux box is running 8.1 FP4 as is the windoze platform. If I am on the linux box i can install...
2
by: Rhino | last post by:
Is there any way to invoke and perform a given subroutine within an SQL procedure several different times, doing other work in between invocations of the subroutine? For instance, let's say that...
2
by: gderosa | last post by:
Hey guys I need some help with local variables, here is my current code: CREATE PROCEDURE CreateFile AS DECLARE @notification int SET @notification = (SELECT NotificationPeriod FROM...
1
by: brianlanning | last post by:
We have a stored procedure that we've tried with two slightly different designs. It needs to take a 30 day date range and return a result set. Design 1 takes one date as a parameter. The other...
1
by: upstart | last post by:
Hi everyone…this is a tough one. You guys have been such a help before, hopefully you can point me in the right direction now. I have a Report I am working on that uses a stored procedure to...
0
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
3
by: stockton | last post by:
I have written the following Stored Procedure in an attempt to update two tables in the same database reliably but unfortunately it is not too successful. I ocassionaly end up with only the...
1
by: rajpar | last post by:
Environment: Solaris (client + server) db2 version 7.2 latest fixpak (DB2 v7.1.0.111", "s050516" and "U803330") Compiler: gcc Here is my SP code executed on the client: CREATE PROCEDURE...
2
by: IuliaS | last post by:
Hello everyone! I want to create a stored procedure, so I can more easily, and transparent retrieve data from db2. Long story short: when a user wants to put some data in the DB, he also creates...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.