Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

sql store procedure query variable usage

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
vbnetcoder
Asked:
vbnetcoder
1 Solution
 
Ephraim WangoyaCommented:

declare @Product_ID int
SELECT @Product_ID = Product_ID FROM Products    
0
 
Paul MacDonaldDirector, Information SystemsCommented:
[ewangoya] is right, but why would you need to query for a product_id you already have?
0
 
vbnetcoderAuthor Commented:
paulmacd:

You are correct... i gave you the wrong query.  The concept is what I needed so thank you.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
Rajkumar GsSoftware EngineerCommented:
>> 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
 
Rajkumar GsSoftware EngineerCommented:
What's ur requirement ?
0
 
vbnetcoderAuthor Commented:
ty
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now