Solved

how insert data from sql in a excel cell depending a cell excel value

Posted on 2012-03-12
6
213 Views
Last Modified: 2012-03-18
hi

is it posible to get a data from a sql table linked to an excel spreadsheet

i have a file named minuta, and i have a sql server with a table named facturas where there are sales data registers.

i want to put the sale import taked from a sql table (dbo.facturacion) , where a field named Numdoc is equal to cell value a2

is it posible it?

thanks a lot
0
Comment
Question by:tenriquez199
  • 4
6 Comments
 
LVL 6

Expert Comment

by:reitzen
ID: 37712605
Yes, this can absolutely be done.  You can do this two ways:
1.  Include the cell value in A2 in your SQL script.
2.  Loop over the "Numdoc" values in your recordset and write the other field values when you find a match.

There are pros and cons to each.

Including the "Numdoc" value from A2 in your script only allows one record to be returned.  Not the most effective if you have a lot of "Numdoc" values to look up.

Looping over the "Numdoc" values in your recordset would be more efficient with a lot of "Numdoc" values in your worksheet, but looping over the recordset multiple times is also not very efficient.
0
 
LVL 9

Expert Comment

by:chwong67
ID: 37712618
0
 
LVL 1

Author Comment

by:tenriquez199
ID: 37715813
hi reitzen

thanks your comment

have you one exapmle?

i try to do it whitout success

thanks
sorry
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 1

Author Comment

by:tenriquez199
ID: 37715837
hi chwong67

thanks your comments

i see reference you give me

i have a dude

how refer or obtain only a value depending a cell value , by example in this code:
With rsPubs
      ' Assign the Connection object.
      .ActiveConnection = cnPubs
      ' Extract the required records.
      .Open "SELECT * FROM Authors"
      ' Copy the records into cell A1 on Sheet1.
      Sheet1.Range("A1").CopyFromRecordset rsPubs
      
      ' Tidy up
      .Close
End With

...................................................................

i think it will be something like this:

With rsPubs
      ' Assign the Connection object.
      .ActiveConnection = cnPubs
      ' Extract the required records.
      .Open "SELECT * FROM Authors where idAuthor = " + "$A1"
      ' Copy the records into cell A1 on Sheet1.
      Sheet1.Range("A1").CopyFromRecordset rsPubs
      
      ' Tidy up
      .Close
End With

..............................................................

you know how can i do that?


thanks a lot
0
 
LVL 1

Accepted Solution

by:
tenriquez199 earned 0 total points
ID: 37716266
hi

i solve it

Function GetSupplierId(cell As Range)
    Dim importe  As Double
    Dim IdDoc As String
    IdDoc = ActiveCell.Offset(, -7)
    Rem IdDoc = cell.Text
 
    Dim conn As New ADODB.Connection
    Dim rs As ADODB.Recordset
    conn.Open ("Provider=sqloledb;Data Source=PCAENRIQUEZ\SQLEXPRESS;Initial Catalog=JDE;Integrated Security=SSPI")
    Set rs = conn.Execute("select importe from Facturacion where idDocumento = '" & Replace(IdDoc, "'", "''") & "'")
    GetSupplierId = rs.Fields(0).Value
 
    rs.Close
    conn.Close
    Set conn = Nothing
    Set rs = Nothing
End Function
0
 
LVL 1

Author Closing Comment

by:tenriquez199
ID: 37734380
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question