Topic: sql vba excel stock-taking of given by date
, I ask the help for I can not invent the code for the following situation:
There is a DB which time is a day filled with the data from registration instruments. To each date there corresponds the certain data. By means of a macro these indications get to a certain column so that they corresponded to date in an adjacent column.
If in a DB there is data for all days of month it is filled correctly And if, for example, for 15 there is no data, and is requested with 1 on 20 instead of cell opposite to 15th to leave empty, it is filled for 16, 16 for 17 etc.
In it all and business: how to make, that at the missing data in a DB in appropriate cells too it was empty, or 0, or not the DATA...
My script of request:
' the Steam conduit 2. Mass' Sub LoadData_id10 () Dim cn As ADODB.Connection Dim rst As ADODB.Recordset Set cn = New ADODB.Connection Set rst = New ADODB.Recordset cn. ConnectionString = "Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=PowerPlant; Data Source=ROCON" ' Parameters of a line of connection cn. Open rst. Open "SELECT VALUE FROM SPNetArchive Where (RequestID=10) AND (DateTime BETWEEN ' 09-01-2017 0:00:00 AM 'AND ' 09-30-2017 0:00:00 AM ') Order By DateTime", cn ' a SQL query, connection, obtaining from column VALUE, on ID and on date-time ActiveSheet. Range ("B72").CopyFromRecordset rst ' It is derived the data on sheet rst. Close cn. Close Set rst = Nothing Set cn = Nothing End Sub
the Moderator: we Learn to use tags of design of the code - FAQ