Discussion Locked

Processing parameters in TransAct SQL

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Here's my problem:

select *
from #my_vars
where sec_type in (select @new_type)

Variable @new_type contains different values (Ex. string1, string2, or "string1","string2") to match one or the other or both. When the var contains string1 or string2, it works. When it contains the combo (this is how I assign the value)

select @new_type = '"string1","string2"'

it doesn't work.

If I hard code the combo in the where clause, like this:

where sec_type in ("string1","string2")

it works.

Maybe it's the version of Sybase that I'm running?..

Thank you,
- Dmitry

3 replies

by agibbs

I've never used Sybase, but in MS SQL (and according the T-SQL standard) that just won't work the way you're doing it . . .

You'll have to store the values for @new_type in a table, and use a statement more like this:

SELECT * FROM #my_vars
WHERE sec_type IN (SELECT new_type FROM table_1)

Best,
Aaron

by dmitryzb.

Aaron,

Thank you for your help. That's actually what I had in mind, but was hoping I didn't have to do that.

Sorry for the delay, I was just waiting to see if I get any other responses. Thanks again,

- Dmitry

This discussion is closed to new replies.