1

I have a asp app that uses the query string value as a parameter to run SQL query1. The results from that query will be used to run query2.

How I pass a value from the result of query1 into query2 in asp?

edit: The two tables are from different databases with different connection settings.

URL: www.website.com?ref=WO123
SQLQuery1: SELECT [valueA],[valueB] FROM TABLE1 WHERE [valueA] = WO123
SQLQuery2: SELECT [infoA],[infoB],[infoC] from TABLE2 WHERE [infoA] =  [valueB]
asp
PWiseGIS.SelectCommand = string.Format(sqldb, SQLQuery1);
asp
PWiseGIS.SelectCommand = string.Format(sqldb, SQLQuery2); with [valueB]

2 Answers 2

0

Your first SQL statement is excessive--you should be able to do this:

select infoA, infoB, infoC from table2 where infoA = (
    select valueB from table1 where valueA = W0123
)

assuming the inner select statement returns a single value

1
  • thanks, the issue is that the two tables are from two different databases with different connections. I've updated the initial query with more details if that helps
    – BobbyGIS
    Apr 16, 2019 at 2:42
0

I would recommend using exists:

SELECT t2.[infoA], t2.[infoB], t2.[infoC] 
FROM TABLE2
WHERE EXISTS (SELECT 1
              FROM TABLE1 t1
              WHERE t1.[valueB] = t2.[infoA] AND
                    t1.valueA = 'W0123'
             );

This will work even when the query on TABLE1 returns more than one row.

1
  • thanks, the issue is that the two tables are from two different databases with different connections. I've updated the initial query with more details if that helps
    – BobbyGIS
    Apr 16, 2019 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.