6
Answers

Sql Querry

Pravin Ghadge

Pravin Ghadge

12y
2.3k
1
Dear all,

I am trying to get net figure using variable.

declare @ConsAcct as nvarchar(1000) 
set @ConsAcct =(select distinct substring((select ''''+ AcctCode + ''',' from oact y where y.fathernum='502000'  for xml path('')),0,LEN((select ''''+AcctCode + ''',' from oact y where y.fathernum='502000' for xml path('')))) from oact x)
---this gives me '502100','502200','502300','502400','503000' in  @ConsAcct variable
select sum(Debit) from jdt1 inner join oact on jdt1.account=oact.acctcode where
 oact.fathernum in (@ConsAcct)

O/P:NULL
but after runnning querry it gives me 'NULL' result

But when i run same query only in place of variable i have hardcoded the no's its give me proper result
select sum(Debit) from jdt1 inner join oact on jdt1.account=oact.acctcode where
 oact.fathernum in ('502100','502200','502300','502400','503000')
O/P:54000

I can't understand what may be the reason....
Plz give me some solution


Answers (6)