Solved

sql store procedure query variable usage

Posted on 2011-03-04
6
308 Views
Last Modified: 2012-05-11
I have this query:

SELECT Product_ID FROM Products WHERE Product_ID = @Product_ID      

I want to put the value of product_ID into a variable so I can use it later in my stored procedure.

How?
0
Comment
Question by:vbnetcoder
6 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
Comment Utility

declare @Product_ID int
SELECT @Product_ID = Product_ID FROM Products    
0
 
LVL 33

Expert Comment

by:paulmacd
Comment Utility
[ewangoya] is right, but why would you need to query for a product_id you already have?
0
 

Author Comment

by:vbnetcoder
Comment Utility
paulmacd:

You are correct... i gave you the wrong query.  The concept is what I needed so thank you.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
>> I want to put the value of product_ID into a variable so I can use it later in my stored procedure.

Make sure you are passing the value for productid to the stored procedure.
@Product_ID  

This will be available all over the stored procedure, no need to modify the query for that purpose.

Your query seems to be have no logic!

SELECT Product_ID FROM Products WHERE Product_ID = @Product_ID

Retrieve productid by passing same product.

Check what you want

If it is something like this, I would say ok

SELECT * FROM Products WHERE Product_ID = @Product_ID
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
What's ur requirement ?
0
 

Author Closing Comment

by:vbnetcoder
Comment Utility
ty
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Word Template Mail merge with vb.net 4 38
Extract XML Data from using TSQL 5 27
Access Date Query 28 28
sql calculate averages 18 21
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

13 Experts available now in Live!

Get 1:1 Help Now