Sending Query Results To MS Excel
Oct 27, 2007
Hi all,
I am just wondering if anyone has a code to send query results to a spreadsheet package eg. MS Excel.
i) Automatically send the query result(s) to the package
ii) open the spreadsheet package;
Thanks.
View 1 Replies
ADVERTISEMENT
Feb 20, 2015
I have been trying to find a way to export the results of a query to a csv for use in excel but cannot.
View 2 Replies
View Related
Mar 8, 2006
Hi,I am using a .dqy file to import some rows from a sql server 2003database to microsoft excel. Unfortunately, I have am importing morerows than excel can handle. Is there a way around this?It appears that there is no equivalent of the LIMIT(offset, number ofrows to return) function of mysql in tsql. Had there been anequivalent, I would have created multiple .dqy files, which would querythe database for pages of results as appropriate. There is an upperlimit to the number of records that there can be in the database, sothis would have been a feasible solution.Also, I must use .dqy files (or something equivalen) because thequeries are invoked from a website, and it is necessary to download theresults, sort/filter, etc. (in excel).Thanks for any suggestions.
View 4 Replies
View Related
May 2, 2007
I'm looking for a tool that can schedule stored procedures or queries and save the results to pdf or excel (preferrably both). SQL Server 2000, so 2005 reporting services are out, though if that has the capability I'd like to know because that might convince some of the powers that be to upgrade.
View 4 Replies
View Related
Dec 1, 2005
Hi,
In SQL Server,
does anybody provide the steps for create a Package for exporting the query results to Excel environment?
I just know that click the "Export", then choose the query file to export to Excel.
I want to know how to create the Package to export it.
Please let me know, thanks.
View 3 Replies
View Related
Jan 2, 2014
Is there a way to export query results to an excel fie and add that file as an attachment in the email? All this has to be done using SQL query and it needs to be automated. My coworker tried using Openrowset and BCP, but it is not working.
View 3 Replies
View Related
Oct 12, 2007
Hi All,
I have two SQL queries that we would like to automate. Ideally we want them to both be scheduled to run and dump their results to a single Excel spreadsheet with two workbooks, one for each query
Is it possible to do this? If not, sending each query to a seperate XLS or CSV file would be OK
Here are the queries:
SELECT p21_view_unvouched_po_currency_report.unvouched_document_type, p21_view_unvouched_po_currency_report.date_created, p21_view_unvouched_po_currency_report.unvouched_document_no, p21_view_unvouched_po_currency_report.line_number, p21_view_unvouched_po_currency_report.po_no, p21_view_unvouched_po_currency_report.po_line_number, po_line.created_by, p21_view_unvouched_po_currency_report.item_id, p21_view_unvouched_po_currency_report.item_desc, p21_view_unvouched_po_currency_report.qty_received, p21_view_unvouched_po_currency_report.qty_vouched, p21_view_unvouched_po_currency_report.order_date, p21_view_unvouched_po_currency_report.location_id, p21_view_unvouched_po_currency_report.supplier_id, p21_view_unvouched_po_currency_report.supplier_name, p21_view_unvouched_po_currency_report.extended_cost_home
FROM P21.dbo.p21_view_unvouched_po_currency_report p21_view_unvouched_po_currency_report, P21.dbo.po_line po_line
WHERE po_line.po_no = p21_view_unvouched_po_currency_report.po_no AND po_line.line_no = p21_view_unvouched_po_currency_report.po_line_number
and
SELECT p21_view_unvouched_po_currency_report.unvouched_document_type, p21_view_unvouched_po_currency_report.date_created, p21_view_unvouched_po_currency_report.unvouched_document_no, p21_view_unvouched_po_currency_report.line_number, p21_view_unvouched_po_currency_report.po_no, contacts.last_name, p21_view_inventory_return_hdr.buyer_id, p21_view_unvouched_po_currency_report.po_line_number, p21_view_unvouched_po_currency_report.item_id, p21_view_unvouched_po_currency_report.item_desc, p21_view_unvouched_po_currency_report.qty_received, p21_view_unvouched_po_currency_report.qty_vouched, p21_view_unvouched_po_currency_report.order_date, p21_view_unvouched_po_currency_report.location_id, p21_view_unvouched_po_currency_report.supplier_id, p21_view_unvouched_po_currency_report.supplier_name, p21_view_unvouched_po_currency_report.extended_cost_home
FROM P21.dbo.contacts contacts, P21.dbo.p21_view_inventory_return_hdr p21_view_inventory_return_hdr, P21.dbo.p21_view_unvouched_po_currency_report p21_view_unvouched_po_currency_report
WHERE p21_view_inventory_return_hdr.return_number = p21_view_unvouched_po_currency_report.unvouched_document_no AND contacts.id = p21_view_inventory_return_hdr.buyer_id
View 4 Replies
View Related
Jul 9, 2015
I am trying to fetch records from excel sheet using Select Query but I am getting the error message saying
"Msg 7302, Level 16, State 1, Line 1
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)"."
Here is my Query,
sp_configure 'show advanced options',1
reconfigure with override
go
sp_configure 'Ad Hoc Distributed Queries',1
reconfigure with override
go
reconfigure
SELECT *
FROM OPENROWSET
('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:M2MworkedworkedBOS.xlsx;HDR=YES', 'select * from [Sheet1$]') AS A;
View 5 Replies
View Related
Dec 10, 1998
I have a 100 mb network and I am returning some large result sets of about 10-50 meg. I am getting through put of sending these resutls of about 2 -3 meg only. I have tried adjusting the client network settings to different protocolsand played with the settings from the performance and tuning guide on Microsofts site.
I am using ADO OLE DB as the connections with VB6.0 as the front end.
When transfering a regular file I am getting between 50 -70 mb through put.
Any help will be greatly appreciated.
Thanks
Tom
View 1 Replies
View Related
Nov 12, 2007
When I used the following code:
Imports System
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Net.Mail
Imports System.Net
Imports System.Data
Imports System.IO
Imports Microsoft.SqlServer.Dts.Pipeline
Imports System.Text
Public Class ScriptMain
Public Sub Main()
Dim msg As MailMessage
Dim smtp As SmtpClient
Dim dt As Data.tbl_clients
Dim ad As New Data.OleDb.OleDbDataAdapter
dt = New System.Data.tbl_clients
ad.Fill(dt, Dts.Variables("User::AllFilesFound").Value)
Dim data As String
For Each row As Data.DataRow In dt.Rows
For Each column As Data.DataColumn In dt.Columns
data = data & (column.StaffNo & " : " & row(column.Ordinal).ToString()) & "<br>"
Next
Next
Dim sendNotify As String
sendNotify = "<pre>Cards to be printed " & Today() & " : <br><br>" & data.ToString() & ""
msg = New MailMessage( _
"my email", _
"my email again", _
"Subject: Cards to be printed", sendNotify)
smtp = New SmtpClient("smtp client")
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
msg.IsBodyHtml = True
smtp.Send(msg)
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
I got the following error:
The query failed to parse. An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
I would like to send an email notification after data has been imported into the table. Any response will be highly appreciated.
Many thanks,
Rupa
View 4 Replies
View Related
Apr 4, 2001
I want to send data to a excel spreadsheet from SQL server 7.
I know that I can create a odbc dsn which points to a table or a view on SQL Server. That works well.
Is there any way to point to a stored procedure.
I want to pull data to a spreadsheet based on a stored procedure.
Any suggestions ?, Is it possible ?
View 5 Replies
View Related
Jan 30, 2008
Hi, when I copy and paste results from query analyzer into Excel it appears that values with zeroes at the end loose the zeroes. Example, if I copy and paste V128.0 into an Excel cell it comes out as V128 or if I copy 178.70 it displays as 178.7 - any ideas? I'm using SQL Enterprise Manager for 2000.
View 6 Replies
View Related
May 18, 2004
Is there a way of running an OS command via xp_cmdshell and sending the results to a spreadsheet within a DTS package ?.
View 2 Replies
View Related
Nov 22, 2005
Hi All
I've been googling this for a while now and can't seem to find any elegant answers.
I'm looking for an automated way to present a FORMATED Excel Spreadsheet to the Customer from a stored procedure output.
Can anyone advise me the best method of doing this - should I / can I assign an Excel Template to the DTS Task output ?
His mind is set on Excel and the formatting is basic and easy to write in a Macro which I've done, but this requires human interaction to finish the task (Automated Run Once on opening etc).
In an ideal world an individual would send an email to the Server with two formated parameters (@FromDate & @ToDate) and would be emailed back a ready formatted S/Sheet. But I believe he would be willing to just select the relevant SpreadSheet for the Daily / Weekly / Monthly periods dumped.
Thanks
GW
View 2 Replies
View Related
Apr 14, 2008
Hi all
When using a subscription to send mail, I find that the report can be sent in any format apart from Excel, which gives me the error: "Failure sending mail: Unspecified error". As you can imagine, this doesn't give me much to go on!
I want to use Excel format as it retains the drilldown functionality (hiding / unhiding rows). The ExecutionLog has the status as rsSuccess, but Subscription tab for the report shows the error.
Any thoughts would be most welcome!
View 3 Replies
View Related
Apr 1, 2007
hi, like, if i need to do delete some items with the id = 10000 then also need to update on the remaining items on the with the same idthen i will need to go through all the records to fetch the items with the same id right? so, is there something that i can use to hold those records so that i can do the delete and update just on those records and don't need to query twice? or is there a way to do that in one go ?thanks in advance!
View 1 Replies
View Related
Feb 12, 2008
Hello. I currently have a website that has a table on one webpage. When a record is clicked, the primary key of that record is transfered in the query string to another page and fed into an sql statement. In this case its selecting a project on the first page, and displaying all the scripts for that project on another page. I also have an additional dropdownlist on the second page that i use to filter the scripts by an attribute called 'testdomain'. At present this works to an extent. When i click a project, i am navigated to the scripts page which is empty except for the dropdownlist. i then select a 'testdomain' from the dropdownlist and the page populates with scripts (formview) for the particular test domain. what i would like is for all the scripts to be displayed using the formview in the first instance when the user arrives at the second page. from there, they can then filter the scripts using the dropdownlist.
My current SQL statement is as follows.
SelectCommand="SELECT * FROM [TestScript] WHERE (([ProjectID] = @ProjectID) AND ([TestDomain] = @TestDomain))"
So what is happening is when testdomain = a null value, it does not select any scripts. Is there a way i can achieve the behaivour of the page as i outlined above? Any help would be appreciated.
Thanks,
James.
View 1 Replies
View Related
Jun 9, 2008
I've got several reports that are sent to recipients in excel format and was wondering if there is any way to have the columns formatted so they are spaced according to the length of the header.
View 1 Replies
View Related
Aug 22, 2001
HI,
I have a small problem with SQL server 7.0 where I have to write the output of a query directly to a file without the user going to the menu and clicking on save. Scenario is:
A file is having a query the results of which has to be outputted to a file like in oracle where we have spooling function. Is there any functionality that mimic the oracle functionality where by I can get the output directly to a file?
thanks for your help in advance.
thanks,
Sravan.
View 2 Replies
View Related
Aug 30, 2007
Hi Guys,
Whats the best way to send a small query result using Send Email Task. I have log table not more then 50 rows with 3 columns I need to query this table and send email.
I tried using Exe SQL Task and in result set I tried to store in variable so that I can attached that variable as email source. I think query result I can't store in string variable like this. Any simple way?
Thank you - Ashok
View 5 Replies
View Related
Jan 12, 2007
Hello,
I have tried to use a DaraReader Source to execute a SQL Server 2000 proc, and send the results to an Excel Destination.
The proc is named spv_CDGetFuelManDuplicates. Within the proc, temporary tables are created and dropped. When I attempt to set 'Exec dbo.spv_CDGetFuelManDuplicates' for the SqlCommand property of the DataReader, I get an error message indicating that my temporary tables are invalid objects.
The DaraReader is using an ADO.NET Connection Manager.
Should I be using an Execute SQL Task instead?
Thank you for your help, the proc code is below.
cdun2
********************************
alter PROCEDURE dbo.spv_CDGetFuelManDuplicates
AS
--Isolate Accounts and Contact Info per the View criteria
SELECT
RTRIM(Acctcode) AS AcctCode,
RTRIM(CompanyName)AS CompanyName,
MMS#, RTRIM(Phone) AS Phone
INTO #CorrectAcctCodes
FROM dbo.DailyAccountsDownload
WHERE
(AcctCode BETWEEN 'IQ001' AND 'IQ999') OR
(AcctCode BETWEEN 'QI001' AND 'QI999') AND (AcctCode NOT IN ('QI125', 'QI601', 'QI603', 'QI613', 'QI623', 'QI653', 'QI697')) OR
(AcctCode BETWEEN 'DQ001' AND 'DQ999') AND (AcctCode NOT IN ('DQ011')) OR
(AcctCode BETWEEN 'FQ002' AND 'FQ999') AND (AcctCode <> 'FQ011')
--Isolate duplicate phone numbers
--per the view criteria
SELECT
RTRIM(Phone)AS Phone, COUNT(*) AS RecordCount
INTO
#DupPhoneNumbers
FROM
dbo.DailyAccountsDownload
WHERE
(AcctCode BETWEEN 'IQ001' AND 'IQ999') OR
(AcctCode BETWEEN 'QI001' AND 'QI999') AND (AcctCode NOT IN ('QI125', 'QI601', 'QI603', 'QI613', 'QI623', 'QI653', 'QI697')) OR
(AcctCode BETWEEN 'DQ001' AND 'DQ999') AND (AcctCode NOT IN ('DQ011')) OR
(AcctCode BETWEEN 'FQ002' AND 'FQ999') AND (AcctCode <> 'FQ011')
GROUP BY
RTRIM(Phone)
HAVING
(COUNT(*)>1)
--Isolate duplicate Company Names
--per the View criteria
SELECT
RTRIM(CompanyName)AS CompanyName,
COUNT(*) AS RecordCount
INTO
#DupCompanyName
FROM
dbo.DailyAccountsDownload
WHERE
(AcctCode BETWEEN 'IQ001' AND 'IQ999') OR
(AcctCode BETWEEN 'QI001' AND 'QI999') AND (AcctCode NOT IN ('QI125', 'QI601', 'QI603', 'QI613', 'QI623', 'QI653', 'QI697')) OR
(AcctCode BETWEEN 'DQ001' AND 'DQ999') AND (AcctCode NOT IN ('DQ011')) OR
(AcctCode BETWEEN 'FQ002' AND 'FQ999') AND (AcctCode <> 'FQ011')
GROUP BY
RTRIM(CompanyName)
HAVING
(COUNT(*)>1)
--Result with duplicate company or phone numbers
SELECT
Acctcode, CompanyName, MMS#, Phone
FROM
#CorrectAcctCodes
WHERE
Phone IN (SELECT Phone FROM #DupPhoneNumbers)
OR
CompanyName IN (SELECT CompanyName FROM #DupCompanyName)
ORDER BY
Phone, companyname
--Drop the temp tables
DROP TABLE #CorrectAcctCodes
DROP TABLE #DupCompanyName
DROP TABLE #DupPhoneNumbers
View 2 Replies
View Related
Apr 29, 1999
Wendy,
I do not know if you can see my reply after yours. Any way I try it here again.
In the DTS Export Wizard, after select the source (SQL Server)and destination (Excel),
I have 2 choices:Table copy or query.
When I use query, I can place my sp there, and the export works fine exactly as you recommended.
Thanks a lot.
But when I selected a table copy, I was given a "Select Source Tables" popup form, I can
see all the table names there, but can not find any views in the database. I do not know why.
Am I in the right place this time?
Thank you very much for your quick help.
Charlie
View 1 Replies
View Related
May 16, 2007
Code:
-- (1) Number of calls received for each priority of call [for a specified date range]
declare @startdate datetime,
@finishdate datetime
select RM.fldPriorityCode as 'Priority',
count(RM.fldRequestID) as 'Calls'
from tblRequestMaster RM
where RM.fldPriorityCode between 1 and 5
and RM.fldRequestDate between '01-01-2007' and '03-05-2007'
and RM.fldRequestFlag like 'D'
group by RM.fldPriorityCode
union
select
'Total' as 'Priority',
count(RM.fldRequestID) as 'Calls'
from tblRequestMaster RM
where RM.fldPriorityCode between 1 and 5
and RM.fldRequestDate between '01-01-2007' and '03-05-2007'
and RM.fldRequestFlag like 'D'
order by RM.fldPriorityCode asc
Results:
PriorityCalls
120
22912
3152
4571
54
Total3659
I would like to transfer these results to an excel sheet. For instance when the user opens up the excel worksheet and types in for a example a start date: 01-01-2007 and an end date: 03-05-2007 (into textboxes) then clicks a button say called 'Get stats' and then the results appear on the sheet.
How can this be done?
View 1 Replies
View Related
May 16, 2007
-- (1) Number of calls received for each priority of call [for a specified date range]
declare @startdate datetime,
@finishdate datetime
select RM.fldPriorityCode as 'Priority',
count(RM.fldRequestID) as 'Calls'
from tblRequestMaster RM
where RM.fldPriorityCode between 1 and 5
and RM.fldRequestDate between '01-01-2007' and '03-05-2007'
and RM.fldRequestFlag like 'D'
group by RM.fldPriorityCode
union
select
'Total' as 'Priority',
count(RM.fldRequestID) as 'Calls'
from tblRequestMaster RM
where RM.fldPriorityCode between 1 and 5
and RM.fldRequestDate between '01-01-2007' and '03-05-2007'
and RM.fldRequestFlag like 'D'
order by RM.fldPriorityCode asc
Results:
PriorityCalls
120
22912
3152
4571
54
Total3659
I would like to transfer these results to an excel sheet. For instance when the user opens up the excel worksheet and types in for a example a start date: 01-01-2007 and an end date: 03-05-2007 (into textboxes) then clicks a button say called 'Get stats' and then the results appear on the sheet.
How can this be done?
View 2 Replies
View Related
Oct 12, 2012
I am running a SQL stored procedure which runs 3 queries on 3 different SQL tables. What is my best option to export the results of these 3 queries to excel?
If it matters they are all SELECT queries, and at most will return < 500 rows.
View 6 Replies
View Related
May 16, 2007
Hi,
I am trying to create a DTS package that uses a sql stored procedure to generate a set of results and export those results to an excel spreadsheet on a server.
The trick is that the stored procedure accepts a parameter for Bank_Number (there are 10 of them). Therefore i was wondering if there was a way to somehow create the package to run the stored proc 10 times, each with a different bank number as the parameter and generate 10 different excel spreadsheets, one for each bank with it's results.
Can this be done using DTS or do i have to try another method?
thanks
scott
View 1 Replies
View Related
Nov 9, 2007
I'm new to Integration Services and going through the learning challenges one often faces when employing unfamiliar technology. I've created a simple package that executes a parameterized stored procedure and returns the results (multiple rows) into an object variable. How do I export the results to an XLS file? Do I have to use a script task to do this?
Regards,
Orlanzo
View 12 Replies
View Related
Sep 13, 2007
I have the following code on a form:
<asp:SqlDataSource ID="building_a" runat="server" ConnectionString="<%$ ConnectionStrings:vol1ConnectionString4 %>"
SelectCommand="SELECT [E_MAIL] FROM [Sheet4$] WHERE ([BUILDING] LIKE '%' + @BUILDING+ '%')" OnSelecting="building_a_Selecting">
<SelectParameters>
<asp:Parameter DefaultValue="a" Name="BUILDING" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="building_b" runat="server" ConnectionString="<%$ ConnectionStrings:vol1ConnectionString4 %>"
SelectCommand="SELECT [E_MAIL] FROM [Sheet4$] WHERE ([BUILDING] LIKE '%' + @BUILDING+ '%')" OnSelecting="building_b_Selecting">
<SelectParameters>
<asp:Parameter DefaultValue="b" Name="BUILDING" Type="String" />
</SelectParameters></asp:SqlDataSource>
<asp:TextBox ID="subj" runat="server" Width="500px">Subject</asp:TextBox><br /><br />
<asp:TextBox ID="messg" runat="server" Rows="20" TextMode="MultiLine" Width="500px">Message</asp:TextBox><br /><br />
<asp:Button ID="bldga" runat="server" Text="Building A" OnClick="Button1_Click" /><br /><br /><asp:Button ID="bldgb" runat="server" Text="Building B" OnClick="Button2_Click" /><br /><br />
<asp:Label ID="resultLabel1" runat="server" ForeColor="red"></asp:Label>
And I have the following code behind:protected void Button1_Click(object sender, EventArgs e)
{SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{MailAddress fromAddress = new MailAddress("me@mydomain.com", "My Name");MailAddress toAddress = new MailAddress("them@theirdomain.com");
message.From = fromAddress;
message.To.Add(toAddress);
message.Subject = subj.Text;message.IsBodyHtml = false;
message.Body = messg.Text;smtpClient.Host = "myhost";
smtpClient.Send(message);resultLabel1.Text = "Email sent!";
}catch
{resultLabel1.Text = "Send failure";
}
}
The queries get e-mail addresses from a SQL database for all people who work in a particular building.
The buttons will send an email if I give a To address.
How do I write the code so that clicking on the "Building A" button will send the e-mail to the addresses from the query results individually?
Any ideas?
View 4 Replies
View Related
Apr 29, 1999
Hi,
Does anyone know the method to transfer result data of a view or stored procedure
in MS SQL 7.0 to MS Access or Excel , Manually or automatically? I did not find the
right tool in SQL 7 to do so.
I notice we can transfer table from SQL 7 to MS Access / Excel through DTS. But did not
find any tool/menu to transfer result of view / stored procedure.
I am new to SQL 7. Maybe this is a silly ?. Any help will be appreciated.
Charlie
View 2 Replies
View Related
Jan 2, 2007
Is it possible to restrict the Users to Export Report Results only to Excel ?
So instead of the default drop down options of csv, pdf, tiff,Web Archive,Web Archive etc... can we get it to just display Excel.
Any help would be appreciated.
View 1 Replies
View Related
Jul 1, 2015
is it possible to replicate this in SSRS I wonder??I have included the code of the fields used and a snapshot of some data, and also how the Pivot looks in Excel.
SELECT
TARNSubmissionID,
ISSBand,
BPTLevelAchieved,
FinancialYearOfDischargeOrDeath,
FinancialQuarterOfDischargeOrDeath,
FinancialMonthOfDischargeOrDeath,
CalendarMonthNameOfDischargeOrDeath,
[code]...
View 4 Replies
View Related
Jun 30, 2015
Goal: To run a stored procedure and export its results to Excel.
Challenge: The stored procedure produces multiple result sets. We want to programmatically export each result set into just 1 Excel file but into different Worksheets. Ex: result set 1 into Worksheet 1, result set 2 into Worksheet 2 and so on. Tools like
BCP utility and OPENROWSET are not enabled for use on the server. So those are out of the league for this one.After I run "EXEC [sp_select_ view_ columns_ from_pp]" -- Within the Results tab of Microsoft SQL Server Management Studio, I see:
viewName columnName columnDataType columnLength column
test test_id varchar 8 0
viewName columnName columnDataType columnLength column
test1 test1_id varchar 8 0
viewName columnName columnDataType columnLength column
test2 test2_id varchar 8 0
As you can see from above, that stored procedure sp_select_view_columns_from_pp is producing multiple result sets within the same Results tab in Microsoft SQL Server Management Studio. We want to make it so it exports to Excel into its own worksheets.
Code:
ALTER PROCEDURE [dbo].[sp_select_view_columns_from_pp]
AS
DECLARE @object_id INT;
DECLARE cur CURSOR FOR SELECT object_id
[code]....
View 7 Replies
View Related
May 28, 2008
ok can someone tell me why i get two different answers for the same query. (looking for last day of month for a given date)
SELECT DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, CAST('12/20/2006' AS datetime)) + 1, 0)) AS Expr1
FROM testsupplierSCNCR
I am getting the result of 01/01/2007
but in query analizer I get the result of
12/31/2006
Why the different dates
View 4 Replies
View Related