May 20, 2008 at 7:54 am
I have this code the pulls the data I want in a time frame from the current time to -1min back
However I have blanks rows, this is the way the database is.
How can I use excel to say leave bank cells out of the record set?
rsRecordset5.Open "select ESASKSIZE AS ESASKSIZE,ESBIDSIZE AS ESBIDSIZE from DBO.DEMANDSPREAD WITH (NOLOCK) WHERE TIMESTAMP BETWEEN DATEADD(mi, -1, " & "'" & DSMAXTS & "'" & ") AND " & "DATEADD(ss, -1," & "'" & DSMAXTS & "'" & " )", gcnConnect
If Not rsRecordset5.EOF Then
Call Sheet4.Range("A2").CopyFromRecordset(rsRecordset5) 'ESASKSIZE
End If
rsRecordset5.Close
End Sub
Regards
Jon
May 20, 2008 at 8:05 am
It's not done by Excel... it's done by the query. Add this to it...
WHERE ESASKSIZE > ' '
AND ESBIDSIZE > ' '
--Jeff Moden
Change is inevitable... Change for the better is not.
May 20, 2008 at 8:06 am
why don't you do it in sql?
and some limits, like
(ESASKSIZE is null and ESBIDSIZE is null)
or
(ESASKSIZE '' and ESBIDSIZE = '')
might work
May 20, 2008 at 8:09 am
forgot to say that records that meet those criteria should not be retrieved.
but i guess Jeff' s idea is faster
May 20, 2008 at 8:12 am
rsRecordset5.Open "select ESASKSIZE AS ESASKSIZE,ESBIDSIZE AS ESBIDSIZE from DBO.DEMANDSPREAD WITH (NOLOCK) WHERE TIMESTAMP BETWEEN DATEADD(mi, -1, " & "'" & DSMAXTS & "'" & ") AND " & "DATEADD(ss, -1," & "'" & DSMAXTS & "'" & " ) ", gcnConnect
If Not rsRecordset5.EOF Then
Call Sheet4.Range("A2").CopyFromRecordset(rsRecordset5) 'ESASKSIZE
'call Sheet4.Range("B2") = rsRecordset5.Fields(1).Value 'ESBIDSIZE
End If
rsRecordset5.Close
End Sub
Sorry I already have a where clause in there, where would I put a second where clause
Jon
May 20, 2008 at 8:15 am
ok this is working for me thats alot for your replys
rsRecordset5.Open "select ESASKSIZE AS ESASKSIZE,ESBIDSIZE AS ESBIDSIZE from DBO.DEMANDSPREAD WITH (NOLOCK) WHERE ESASKSIZE > '' AND ESBIDSIZE > '' AND TIMESTAMP BETWEEN DATEADD(mi, -1, " & "'" & DSMAXTS & "'" & ") AND " & "DATEADD(ss, -1," & "'" & DSMAXTS & "'" & " )", gcnConnect
If Not rsRecordset5.EOF Then
Call Sheet4.Range("A2").CopyFromRecordset(rsRecordset5) 'ESASKSIZE
End If
rsRecordset5.Close
End Sub
May 20, 2008 at 10:24 pm
You bet... the columnname > '' keeps out Nulls and Blanks and still allows an index to be used.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 21, 2008 at 8:36 am
There is one thing, I need the record setto come through sorted from oldest to newest, I have a time stamp or I could add a field that i can sort on
what would i need to do to tell the recordset to sort, currently the record set is not sorted as i would like
it appears to be jumbled up in areas
May 21, 2008 at 8:57 am
So stupid its order by in sql, where i need to do it not in excel
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply