Reputation: 562
I have a question on the sql IN query. For example you have table with columns id, amount name.
With a query:
SELECT SUM(amount) FROM table WHERE id IN (101,101);
What I want with this is to add amount of a certain id. Whatever the id is inside the IN statement. If like this, two 101, amount of 101 + amount of 101.
The problem is it consider it is one instance. How do I do this? its suppose to be:
SELECT SUM(amount) FROM table WHERE id IN (SELECT id FROM table.........);
Which the sub select return "101, 101".
How
Upvotes: 0
Views: 133
Reputation: 588
I do something like this
Select * From table1
inner join dbo.fnSplit(@ArgList, ',')
That would definitely work for me
Upvotes: 0
Reputation: 107736
SELECT SUM(tbl.amount)
FROM tbl
JOIN (select 101 id UNION ALL
select 101) InList on InList.id = tbl.id
Expand this way.
Upvotes: 2