简体   繁体   中英

Selecting parameter from values of a SQL Query

I need to produce a report that selects a set of values from a database table based on a company. I would like the user to be able to select the name of the company from a list of available companies. The companies have 2 associated unique database ID code number. Based on what companies the user selects I need the sql query to pass to the parameter both unique codes to the parameter. So, in short, how do I create a sql query that would show the company names and when selecting the company would then select both unique codes based on the company name I select from a single select drop down. Use the value selected from that drop-down list to run the SQL query in the report itself?

Thanks for any help or advice you can offer!

Pass the company name to to your stored proc instead of the two unique codes, then find the codes for the company inside your procedure.

CREATE someProc (@Company VARCHAR(100))
AS BEGIN

DECLARE @ID1 INT, @ID2 INT

SELECT @ID1 = someID1, @ID2 = someID2
FROM someDatabase
WHERE companyName=@Company

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM