sql - Is it possible to select a column from a database and not display it in the result set - if selected, causes an issue with Group By -


i have query that's being use in application. had make small edit (select additional column) , that, don't same results, therefore bad file. give example query looks ....

select      'x' = tbla.vendornumber,      'y' = tblb.label,      'z' = tblc.invoiceno,      'w' = tbld.checks,  //doing joins here group      tbla.vendornumber, tblb.label, tblc.invoiceno, tbld.checks 

the result set gives me many records, groups ones identical x,y,z,w - no group this

x                y                 z                  w ----------------------------------------------------------- 123              anton             772                0 123              anton             772                0 

obviously, group rolled one...

the issue comes when try include additional column in select query. need query in my, because need value in code able distinguish type of record is. new column, these 2 rows of data not same, therefore not rolled up.

is there way me somehow add additional column, not display it, , exclude group by?

this mean

select      'x' = tbla.vendornumber,      'y' = tblb.label,      'z' = tblc.invoiceno,      'w' = tbld.checks,      'p' = tblc.proc     -- new column //doing joins here group      tbla.vendornumber, tblb.label, tblc.invoiceno, tbld.checks,     tblc.proc       -- new column 

in case data looks this

x                y                 z                  w          p --------------------------------------------------------------------- 123              anton             772                0          fpn 123              anton             772                0          ppn 

so p different 2 records rolled one, there way me somehow not display p, however, still able it's value record set. unable select 'p' if it's not selected in 1 query , because of fact 2 records not rolling up, i'm having major issues.

basically need select 'p' not include in result set or group by.

any appreciated.

there's couple of options, guess... there's not way values without having them in results. how else read them?

one stuff values of 'p' comma delimited list ie:

x                y                 z                  w          p 123              anton             772                0          fpn,ppn 

then read them in application separated comma. read here: https://stackoverflow.com/questions/31211506/how-stuff-and-for-xml-path-work-in-sql-server

another create boolean headers if there's not many options 'p' or know of options. can create them using case statements like:

,sum(case when tlbc.proc = 'ppn' 1 else 0 end) "ppn" 

edit: left out aggregate around groups correctly. can use max, 1 or 0, well... depends how many results there can tlbc.proc. aggregate function around cases combine rows one.

for results like:

x                y                 z                  w          fpn          ppn          anotherp 123              anton             772                0          1          1          0 

third, if misread question , don't need values need them in where, don't display them.

there's more ways go this.

does help?


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -