Announcements
No record found.
I need filter the field value in a computes column, is possible?
Are very much select, my other option is create un store procedure
thanks in advance
*This post is locked for comments
Method for a computed column should return you SQL statement that would be injected in your SQL view definition. You cannot use any selects or logic there. However, if range you want to use is a constant or a field from the same table then you can use it in the where statement. Usually it's easier to build sub select in SSMS first, test it and then convert to computed column.
I already did it by sql, but I need a DECLARE and it is not allowed in the column. There are 3 queries, Table A does not bring results, I look in Table B, Otherwise in Table C
Could you please provide more details? Like why do you need DECLARE ?
STR VALUE = SYSCOMPUTEDCOLUMN::RETURNFIELD(MYFIELD); SELECT FIELD1 FROM TABLEA WHERE TABLEA.FIELD == VALUE; IF(TABLEA) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEA.FIELD1); } ELSE { SELECT FIELD1 FROM TABLEB WHERE TABLEB.FIELD == VALUE; IF(TABLEB) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEB.FIELD1); } ELSE { SELECT FIELD1 FROM TABLEC WHERE TABLEC.FIELD == VALUE; IF(TABLEC) { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(TABLEC.FIELD1); } ELSE { RETURN SYSCOMPUTEDCOLUMN::RETURNLITERAL(''); } } }
i like do this. depending on the value of VALUE, I consult in different tables
and in sql it would be something like that
DECLARE @MYVAR VARCHAR(20); SELECT @MYVAR = FIELD1 * FROM TABLEA IF(@MYVAR=='') BEGIN SELECT @MYVAR = FIELD1 * FROM TABLEB .... END
You dont need declare, it can be done using "case" here is an example of SQL statement getting data from different tables:
select itemId,
case itemId
when 'BRMF010' then (select top 1 SalesId from SALESLINE where itemId = itemId)
else (select top 1 Purchid from PURCHLINE where itemId = itemId)
end myColumn
from INVENTTABLE
Thanks But how i can validate if the first table has 0 rows, search in second table?
select case when exists (select 1 from TableA where ...) then (select top 1 SalesId from TableA where ...) else (select case when exists (select 1 from TableB where ...) then (select top 1 SalesId from TableB where ...) else (select case when exists (select 1 from TableC where ...) then (select top 1 SalesId from TableC where ...) else ('') end) end) end
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CP04-islander 39
Michel ROY 14
imran ul haq 8