on 2010 Oct 04 11:05 AM
I have to deal with an older database. In this database no relation was used, instead the references have been stored as a comma separated list 😞
Now I need to execute a statement like this
select * from x where xid in ( 1,2,3 )
My problem is, that 1,2,3 is a value stored in one row of another table
select xid from y where yid = 1 => '1,2,3'
So how to combine this in SQL? My naive approach
select * from x where xid in ( select xid from y where yid=1 )
results in: convert 1,2,3 to numeric not possible.
Request clarification before answering.
If you are on V10+, you can use sa_split_list() system procedure to break comma-separated list into individual items, like this:
select * from x where xid in ( select row_value from sa_split_list (select xid from y where yid=1 ), ',')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Dmitri: the idea is ok, anyway sa_split_list is not accepting the select, but it works if I use a temporary variable instead
@Volker: You can't use a query as a parameter to a function/procedure call so Martin's solution of using a temp variable is the way to resolve the issue.
User | Count |
---|---|
75 | |
30 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.