I have the following query:
select CONCAT('PtdBal',(select right(substring(PerNbr,5,2)-1+100,2) from SLApplication.dbo.GLSetup))
from SLApplication.dbo.AcctHist
where substring(Sub, 16, 6) = '189621'
and acct like '822%733%'
and PtdBal05 < 0
and fiscYr = (select substring(PerNbr, 1, 4) from SLApplication.dbo.GLSetup)
and LedgerID = '02'
Which gives me the following result:
| (sin nombre de columna)
----|------------------------
1 | PtdBal05
But it turns out that PtdBal05
is the name of the column. How can I get the records / records that the column has? Can I do this in the query without using a Store Procedure or do I necessarily have to use a Store Procedure? I would prefer that this be done in the query. Is this a dynamic query?
Thanks for the help.