473,813 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored Procedure Local Variables

86 New Member
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 2400
BHARATH RS
6 New Member
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_Practis e.dbo.Cust_Reco rd)

print @l_top_customer

END
GO
Jun 12 '07 #2
enreil
86 New Member
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_Practis e.dbo.Cust_Reco rd)

print @l_top_customer

END
GO
Jun 12 '07 #3
Motoma
3,237 Recognized Expert Specialist
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
10452
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 change the parameter data types to the actual data type such as varchar(10), etc., the stored procedure takes less that a second to return records. The user defined types are mostly varchar, but some others such as int. They are all input type...
7
3261
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 the sample jdbc stored procedures o.k. For the purpose of this test I created a sample procedure that executes "select * from department" when conected to the sample database on the linux box.
2
339
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 I want my SQL procedure, named A, to call another SQL procedure, named B. After A calls B, A needs to process the two result sets returned by B, which involves allocating cursors for each of the result sets. Then, A needs to call B again a few...
2
16422
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 Notification Where NotificationID = 1) SET NOCOUNT ON --Populate template
1
1604
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 date is calculated in a local variable to be 30 days before the one that was passed in. Both data types are datetime and are in the where clause. Design 2 takes two dates as parameters with the 30 days being calculated outside the stored...
1
1755
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 pass along all off the parameters to the reporting generator (Crystal Reports) and I was currently trying to optimize it for my users, but am not sure of the best way to go about doing it. It took me forever to get it to work as it is now. I...
0
3195
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 fine. Now we decided to move from mainframe IMS-DB2 to Windows 2003 server-DB2 UDB for LUW 9.5.
3
2545
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 BundlesIssued tables updated and nothing in TicketsIssued. Please make suggestions on how I could make this stored procedure update both tables reliably. ALTER PROCEDURE spIssueScannedTickets @iEventID int, @MemberNum nvarchar(12), ...
1
5036
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 db2user.x (IN value INT) LANGUAGE SQL BEGIN INSERT INTO db2dba.t1 values (value);
2
5657
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 the tables and their links. When getting the data from the DB... well suffice to say it's ugly. I want to use one stored procedure that will return a result set as (name, value) pairs so I can display it nice and easy in the UI. So far I've managed to...
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10667
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10407
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10422
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9222
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.