简体   繁体   中英

VB6 and SQL report in Excel

I'm making an excel extract out of some data that I'm pulling from SQL Server. I came across a small issue that I would like to ask you guys how to proceed. Basically I'm running a report that will include ClientName and 5 answers.

Name....Q1....Q2....Q3....Q4
JOHN     1     2     2     2

The thing is, I need to display values 1-5 on the extract, but the values saved are 1801 - 1805. How should I manipulate the data for the extract. Should I just do a case statement inside my SELECT statement, something like...

Select FirstName, LastName, case when Q1 = 1801 then '1', when Q1 = 1802 then '2'.... 

the thing is i might have to do it for all questions....?

This report will be written in a VB6 application -- so what i'll do is pull this data, and then loop through each recordset and just write it all to excel.

As you are intending to loop through the recordset to display it, putting the case select in the SQL is unnecessary and will make it harder to debug. You are better off with your logic in vb.

However, as an alternative you can use the .copyfromrecordset function in excel to dump the whole recordset into a sheet. If you do this then you need the SQL to include the case select as it is more complicated to manipulate the recordset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM