question

Sunshine15 avatar image
Sunshine15 asked

Pass a multiple values variable to another table

I want to declare a variable @Number which has multiple values got from Table1 and pass to Table2. How to do that? SELECT NumberNo From Table1 SELECT * FROM TABLE2 WHERE COMMENT LIKE '@Number'
sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tom Staab avatar image
Tom Staab answered
I think there are a couple of ways to solve your problem, but I'm not entirely sure what the values are and why you are using LIKE. I'm assuming you want to return every row from Table1 with a comment that includes a number from Table1. For simplicity, I'm also assuming NumberNo is actually a varchar data type. My first suggestion is to avoid the variable entirely. SELECT * FROM Table2 t2 WHERE EXISTS (SELECT 1 FROM Table1 t1 WHERE t2.Comment LIKE '%' + t1.NumberNo + '%') ; If that doesn't work they way you want it to, please comment with more details so I (or someone else) can provide a better answer.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.