mardi 26 juillet 2016

if exits in sql within a subquery

I am trying to execute the following query to check the records from the 4 tables and then calling a function,but i get an error near the brackets.It works fine if I use case,but exits when the first condition is met. I need to evaluate for all the tables in the 4 IF's:

select account_id, ( if exists (select account_id from [dbo].[TEST_R6]) begin select dbo.make_indicator(cent,chem,co,dim,lg,pl,strs,vis) + space(1) + 'rr' end

                if exists (select account_id from tbl_noR6) 
                begin
                 select dbo.make_indicator(acent,chem,co,dim,lg,pl,str,vis) + space(2) + 'cc'
                end


                if exists (select account_id from tbl_acct) 
                begin
                 select dbo.make_indicator(cent,chem,co,dim,lg,pl,str,vis) + space(3) + 'pp'
                end

                if exists (select account_id from test_con) 
                begin
                select dbo.make_indicator(cent,chem,co,dim,lg,pl,str,vis) + space(4) + 'no'
                end

                )as value


            from CRS_PRODLINE

Aucun commentaire:

Enregistrer un commentaire