Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

Pivot SQL results in DataGrid

$
0
0
I have many fields in a SQL database. I have a query that extracts the count of 50+ different fields on certain topics. The query then spits the data into a DataGridView. However, the data is in columns and I want to put it in rows. How do I pivot the data that is extracted?

Here is my SQL statement.....
SELECT DISTINCT ABS(Sum(fldAddress)) AS 'Address Change', ABS(Sum(fldAgedAcct)) AS 'Aged Accounts', ABS(Sum(fldARMSE)) AS 'ARMSE', ABS(Sum(fldAuth)) AS 'Auth to Release Info', ABS(Sum(fldDROP)) AS 'BackDROP', ABS(Sum(fldBenef)) AS 'Beneficiary', ABS(Sum(fldStmts)) AS 'Benefit Statement', ABS(Sum(fldCashOut)) AS 'Cash Out', ABS(Sum(fldChecks)) AS 'Checks',
ABS(Sum(fldCOLA)) AS 'COLA', ABS(Sum(fldCom)) AS 'Complaint', ABS(Sum(fldCons)) AS 'Conservator/Guardian', ABS(Sum(fldContRef)) AS 'Contributions/Refunds', ABS(Sum(fldCURP)) AS 'CURP',ABS(Sum(fldDBO)) AS 'DBO', ABS(Sum(fldDeath)) AS 'Death Notification', ABS(Sum(fldDesAgent)) AS 'Designation of Agent', ABS(Sum(fldDirBill)) AS 'Direct Bill',
ABS(Sum(fldEFT)) AS 'Direct Deposit', ABS(Sum(fldAffidavit)) AS 'Family Member Affidavit', ABS(Sum(fldIncVer)) AS 'Income Verification', ABS(Sum(fldLegal)) AS 'Legal Hold', ABS(Sum(fldLeg)) AS 'Legislation', ABS(Sum(fldIns)) AS 'Life Insurance', ABS(Sum(fldLifeIncrease)) AS 'Life Insurance Increase', ABS(Sum(fldLTD)) AS 'LTD', ABS(Sum(fldMil)) AS 'Military Purchase',
ABS(Sum(fldNews)) AS 'Newsletters', ABS(Sum(fldOther)) AS 'Other', ABS(Sum(fldOtherSys)) AS 'Other Systems', ABS(Sum(fldOutCountry)) AS 'Out of Country', ABS(Sum(fldPayRec)) AS 'Pay Record', ABS(Sum(fldPayP)) AS 'Payroll Personnel', ABS(Sum(fldPOA)) AS 'POA', ABS(Sum(fldDown)) AS 'Pop-Down', ABS(Sum(fldUp)) AS 'Pop-Up', ABS(Sum(fldPur)) AS 'Purchasing Service', ABS(Sum(fldRet)) AS 'Retirement', ABS(Sum(fldMail)) AS 'Returned Mail', ABS(Sum(fldSalary)) AS 'Salary', ABS(Sum(fldSecurity)) AS 'Security', ABS(Sum(fldSem)) AS 'Seminar', ABS(Sum(fldSrv)) AS 'Service', ABS(Sum(fldSick)) AS 'Sick Leave', ABS(Sum(fldSur)) AS 'Survivor', ABS(Sum(fldTaxes)) AS 'Taxes', ABS(Sum(fldWebSite)) AS 'Web Site', ABS(Sum(fldWalk)) AS 'Walk In' FROM calls WHERE fldTime BETWEEN '2015-09-25' AND '2015-09-26' AND fldSection='Benefits' AND fldIn=1

This is how it displays....
Name:  types.jpg
Views: 4
Size:  20.7 KB

But I want it to display like this (field in left column and the sum in the right column).....
Name:  old types.jpg
Views: 3
Size:  21.1 KB

Thank you for your assistance!!
Attached Images
  

Viewing all articles
Browse latest Browse all 2918

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>