Is it possible to get a Computed column in one table to carry out a SELECT & SUM from a column in another table? I have tried a SELECT / FROM / WHERE construct but SQL complains about that.
Regards
Clive
Pretty sure you can do it. Will you be able to give the table structures and what you want to achieve, and version of your SQL?
|||Hi Jack
Sure:
Table: Transactions, structure id:int, tdate:datetime, Description:NCHAR(20), Value:int
In another table id' like a computed column that in effect is:
SELECT SUM(Value) FROM Transactions WHERE Description='Credit'
I've tried entering this into the computed column slot but SQL complains.
The version of SQL server I am suign is SQL 2005
Regards
Clive
|||
I assume your other table [OtherTable] has structure like: ID [int], somethingelse [varchar], AND [ID] field is the SUM of some criteria from your table [transactions].
Then the query can be:
SELECT *FROM OtherTable otINNERJOIN (SELECTSUM([value]) tvalFROM transactionsWHERE [description] ='credit') tON ot.[id] = t.tvalsqlsql
No comments:
Post a Comment