EXCEL 2007 macro
Posted
by
Binay
on Super User
See other posts from Super User
or by Binay
Published on 2013-06-25T13:26:58Z
Indexed on
2013/06/26
10:23 UTC
Read the original article
Hit count: 167
microsoft-excel
|macros
I have a macro which connects to db and fetches data for me and makes it comma separated. But the problem is the comma is getting appended to the last row, which I don't want. I'm struggling here. Could you please help out?
Here is the part from the code.
If cn.State = adStateOpen Then
Rec_set.Open "SELECT concat(trim(Columns_0.ColumnName), ' ','(', 'varchar(2000)' ,')') columnname FROM DBC.Columns Columns_0 WHERE (Columns_0.TableName= " & Chr(39) & Tablename & Chr(39) & "and Columns_0.Databasename=" & Chr(39) & db & Chr(39) & ")ORDER BY Columns_0.Columnid;", cn 'Issue SQL statement
If Not Rec_set.EOF And Not Rec_set.EOF Then
Do Until Rec_set.EOF
For i = 0 To Rec_set.Fields.Count - 1
strString = strString & Rec_set(i) & ","
Next
strFile.WriteLine (strString)
strString = ""
Rec_set.MoveNext
Loop
Here is the result I am getting.
EMPNO (varchar(2000)), ENAME (varchar(2000)), JOB (varchar(2000)), MGR (varchar(2000)), HIREDATE (varchar(2000)), SAL (varchar(2000)), COMM (varchar(2000)), DEPTNO (varchar(2000)),
I don't want the last comma.
© Super User or respective owner