Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Dynamic Query

Author  Topic 

devonkyle
Starting Member

19 Posts

Posted - 2003-07-18 : 14:34:16
I have a stored procedure that is using about 20 columns/values from a specific row in table 'A' as the @paramaters/variables being used in a SELECT statement against table 'B". What would be the best approach to code this?

I already have a foreign key that links the two tables. I know there must be an easier way to code this then setting each of my 20 paramaters using 20 lines of SET @variable = (select column from TableA where....)

For Example

SELECT * from TableB
WHERE @x = (value for field 'X' in TableA)
Where TableA.orderid = @orderid


Thank you in Advance
Devon Kyle

nr
SQLTeam MVY

12543 Posts

Posted - 2003-07-18 : 14:38:53
You mean for each value in a column in a row in A you want the value of a corresponding row in B?

Funny structure

select *
from Table B
where x in (select col1 from tableA where orderid = @orderid union select col2 from tableA where orderid = @orderid union ...)



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

devonkyle
Starting Member

19 Posts

Posted - 2003-07-18 : 14:54:58
Yes - that is what I mean - The query is for an online search system and the paramaters for the queries are being stored for later reference for the user. Also , some of the paramaters are global for all users queries and some change with each query. The global paramaters are what I am storing in my Table A.
The example you gave me is how I'm doing it, I thought there would be an easier way than that. Thank you for your reponse.

Go to Top of Page
   

- Advertisement -