set dateformat 'dmy' select count(c.id), e.name from call c left outer join employee e on c.req_id = e.id where c.posted between '01/01/2002' and '30/11/2002' group by e.name order by count(c.id) desc
set dateformat 'dmy' select count(ch.id), e.name from call_hist ch left outer join employee e on ch.req_id = e.id where ch.posted between '01/01/2002' and '30/11/2002' group by e.name order by count(ch.id) desc
the results:
42NULL 34Dirk Deloof 13Annick Leirman 11Ronny Loosen 9Geert Benoot 9Nicole Ferrari 8FLOCK 8Mosselmans Christoph 7Geert Pets 7Mireille Dutrieue 6johan 6Laurent De Schrijver 5Jeanette De SChrijve 5Marc De Vlieger 5minerva 5Pascal Saesen 5Rik Haghebaert 5Sonja Van Kerckhove 4Bcatron 4Luc Willems 3Brigit Brocken 3euroadmin 3Francine Kopp 3Luc Steyaert 3Marie-Rose Buysse 3Marnix Van Steirtege 3Mattias Denys 3Pieter Frooninckx 3Reserve 3Rik De Scheemaecker 3Thierry Linard 2Carlos Van Alboom 2Dorine Sierens 2Els Poelman 2Jean Claude Vermeir 2Katrien Colman 2Kim Impens 2Kris Lejeune 2MEDreserve01 2Roger De Wilde 1Agnes Lebon 1Carla Van Den Broeck 1Eric Vlaeminck
and
118NULL 58Marie-Rose Buysse 47Dirk Deloof 45Ronny Loosen 43Annick Leirman 41Geert Pets 38FLOCK 38Pascal Saesen 28Teamleiders afwerkin 24Kim Impens 22Ilse Soetens 22Rik Haghebaert 22Severine Balduck 21Teamleiders print 20Mosselmans Christoph 20Jeanette De SChrijve 19Geert Benoot 19Francine Kopp 18Geert Meuleman 17Rik De Scheemaecker 16johan 16Katrien Colman 15Gaby Eloot 14Kris Lejeune 14Gilbert Callebaut 14Laurent De Schrijver 13Els Poelman 13Luc Steyaert 11Marnix Van Steirtege 10Frans Hoogewijs 10Sonja Van Kerckhove 10Dorine Sierens 9Eric Vlaeminck 9Thierry Linard 7Frederic Denis 7Michel Poppe 6Carla Van Den Broeck 6Pieter Frooninckx 5Katlijn Poleyn 5MEDreserve01 5Mireille Dutrieue 5Agnes Lebon 4Guido Antoin 4Onderhoud 4minerva 4Jeanette Van Brussel 3Roger De Wilde 3Sofie Gabriels 3Verf2 3euroadmin 3Marc De Vlieger 2Luc Willems 2MEDRESERVE07 2Regina Decoster 2Monique Kohl 2MEDRESERVE04 2Portier 2Bcatron 2Pierre Hanet 2Tgabriels 2Isabelle Torrelle 2Nicole Ferrari 1Robert Zwaak 1Carlos Van Alboom 1testuser 1Brigit Brocken 1Reserve 1Opleiding 1Verf
How do I put these results in one? I need not two but one Query. Please help me. Thanks
I have a sub report that returns a variable amount of results. On occasion many results will be returned and cause one or more extra pages to be created.
The results from my sub report are not very wide so what I would like to do is have the results roll over from the left hand side of the page to the right hand side of the page and then continue this pattern on sunsequest pages until all results are displayed. Very similar to newspaper columns.
Is this possibe? If so how can I go about doing this?
Im running a query using isql from the command line and outputting the results to a file. Ideally I'd like to have the file in csv format so that it can be used by a client to import the results into their system.
I can run a query and output the results to a file but get i dont get the csv format I require. I can separate the columns using /s parameter but I also additional space within the column fields.
I know it is possible to create the csv format using the SQL query tool and ISQL_w but I was wondering if there was some parameter that I can call that will format the output like the format options in ISQL_w allows me to do.
Is there a way in SQL Server 2000 to output your query results to a file (example comma-delimited) in the SQL CODE ITSELF? I know you can check the option under Tools->Options->Results but I want to have it do it in the SQL code. Thanks Eric
I have a query (select * from table1) and I'd like to have the results of this query sent to a text file instead of the results windows when I run it from Query Analyzer.
I want to write a small program (maybe just a stored procedure) that will save the results and column names of a simple query to CSV file. This will then be copied onto disk and distributed to user who'll use Excel or a similar package to open the CSV file.
Any suggestions as to the best way to achieve this? I was considering using a view and then BCP but I have problems then when trying to open the CSV file in excel (or other spreadsheet package). Doesn't like the datatypes and so on.
Is there a simple way to do this? And is it possible to save the results in such a way that Excel will choose the right datatypes for the columns. (not convert varchar's like '000122' to numbers.)
select *,substring(stafflog,15,11) as test into #t1 from dbo.Customers where stafflog like '%armagh%' go select left(stafflog,4) as Staff,count(left(stafflog,4)) as Total from #t1 where cast(left(test,charindex(' ', test))as smalldatetime) = cast(convert(varchar(8),getdate()-1,1) as datetime) group by left(stafflog,4) go select Title,Address1,Address2,Town,County,Postcode,TelephoneDay,TelephoneWork,TelephoneEvening, MobileTelephoneNo,Contact,Mail,Telephone,Terms,StaffLog from #t1 where cast(left(test,charindex(' ', test))as smalldatetime) = cast(convert(varchar(8),getdate()-1,1) as datetime) go drop table #t1 go
i need this query to be scheduled to run at a certain time every day and the results to be put in a text file.
is there an easy way to do this or what should i be looking at doing to get it to work
After running a query (from the Query Builder) in SQL Server 2008 sometimes I can right-click on the results pane and "Save results as CSV file", other times it's not an option. After running a query for 24 hours (several million record results) I can't seem to do anything with the results. I have my settings:
Options | Query results | SQL Server | Default Destination for Results
set to "Results to File" and a path entered, but it doesn't work. Is there wording I can add to the end of my SQL statement such as "TO FILE xxx.csv" or something?
is there a way to print query results from mgt studio into a file with headings and formatting? When I "save as a" file, export file, spreadsheet, the results dont have headings and semi decent formatting.
I have written a query that I need to save results of. Is there some statement that I can place at the top of my query (like we can do in Oracle through spool command) to specify the directoryfilename to save query results to? Eventually I need to schedule this to run daily via a DTS package.
Please let me know if you've come across this before?
I have posted this on previous forums, but the below code is a VB.net CLR stored proc that will accepts two parameters, a SELECT.... FOR XML query and a file path, and saves the resulting xml result into a file specified by the parameter. After compiling the VB code into a .dll than the T-SQL code to import the assembly, create the CLR proc and test it is included underneath. Hope some will find this useful
Code Snippet 'Requires the Trial or Release version of Visual Studio .NET 2005 Professional (or greater). Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Data.SqlTypes Imports Microsoft.SqlServer.Server Imports System.Xml
Partial Public Class outputxml <Microsoft.SqlServer.Server.SqlProcedure()> _ Public Shared Sub outputxml(ByVal XmlData As SqlXml, ByVal Filename As SqlString) 'Create the variables to hold the values that are supplied by the parameters 'input by the stored procedure Dim xmlDoc As New XmlDocument() Dim output As SqlPipe = SqlContext.Pipe() Try 'Load the result set into the XmlDoc Variable and then save the results in the 'path provided by the stored procedure. The values are provided by the 'input parameters of the stored procedure xmlDoc.LoadXml(XmlData.Value) xmlDoc.Save(Filename.Value) Catch ex As Exception 'If an error occurs catch the message and pipe it back to SQL output.Send(ex.Message.ToString) End Try End Sub End Class
T-SQL CODE BEGINS HERE
/*Alter the database to set trustworthy on in order
to allow the ability to set the assembly to external
Hello, We have some queries that are long and intensive. We have thought about running the queries and storing the data in a text file for lookup from our website.
Example: Our online store only displays items that are in stock so when a user selects a category a query runs and grabs only items that are in stock and then displays them. There could be thousands of items the query needs to sort through before displaying the items that are in stock. What if we ran this query once every hours an stored the results in a txt file? The asp page would then go to the text file to grab the results instead of having to run the query every time a user selects a category. Will this speed up the site by not having to query every time? Would this be a correct way to eliminate queries that run thousands of times a day?
Hello, I'm pretty new to SSIS but so far what I have is a package that exports a SQL Server table to a text file. I needed to add a dynamic header that had the date and time of creation. Now I need to know how many records are being exported and put that number into the header.
For the header I am using a script task in the control flow which works well to put the creation date in the header. The script runs and writes the header and then the data flow exports and appends the records to the same text file. It seems to me since the script runs before the data flow I won't know the amount of records until after the data flow is done.
Maybe I could write the header after the data is gathered but before it is exported. Can anyone make some suggestions?
Basically the text file would be:
2/6/2008 154 Data Data Data ...
the 154 would be the total number of records to follow.
While I'm at it can someone tell me how to access the destination file path in the flat file connection? Right now I'm just hardcoding the path into my script.
I have the following code below where I need to have all of the query results output into a .csv file to use in a VBA macro. The issue I am running into is that the data is not deliminating correctly and my rows are being shifted incorrectly. Any better way of out putting the results into a .csv file with a common delimiter.
Output from query (please post in a text editor. The line starting with (only ) should be on line 1 after 20 pks and is shifted to a new line.):
557898^1^9885E25^80082^9.0 CM GLASS FIBER PADS 20PKS (only 12 pks in stock that will ship today) ^12.00000000^.00000000^18.32000000^219.84000000000^28.30000000 ^339.60000000000^9.98000000^35.2650176678445^DR9146322^0^
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.
I am using vs 2005 and sqlserver 2005 to manage a large database. I need to create a series of text files based on the value of one of the columns. Is there an sql command that will pipe the output directly to a file?
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
I need to analyze the results from Table 1, count how many records there are where one field matches, and then put some of Table 1's information into Table 2 along with the count of the records that match. This is built to interface with another system, so a lot of the information, names, and relationships can't always be changed.
Table 1: tblResourceAllocation Fields (Description):ID (Unique)LastName (Unique alphanumeric string for each employee, but one employee can have multiple records in this table)Project (Unique name, can have multiple entries in this table)Owner (Unique alphanumeric string for each owner, but one owner can have multiple records in this table)ResourceStartDate (datetime)ResourceEndDate (datetime)ServiceID [I](this is what I want to aggregate)Status_FC [I]
Table 2: tblGRFM ID (unique)Pm (the tblResourceAllocation.Owner's actual full name, which I'll look up from an EmployeeData table and concatenate the FirstName and LastName)IdClient (from tblResourceAllocation.Project I will look up the Customer from the Projects table, then look up the Customer ID from the Customers table)US_State_Id (look up State from Projects table then ID from tblStateCodes)Project_name (same as tblResourceAllocation.Project)Status (same as tblResourceAllocation.Status_FC)Id_operlst (same as tblResourceAllocation.ServiceID)Start (earliest start date of relevant entries)end (latest end date of relevant entries)Nb_ress (total number of ResourceAllocation entries that match Id_operlst)Cadence (explanation below)
I need to calculate how many of each serviceID's are in table 1, and then store that calculation and the ServiceID (Id_operlst) in table 2I need to separate those calculations by Owner, IdClient, US_State_Id, and Project_Name I.E. If there are 5 entries in table 1 with ServiceId = X, and Owner A is listed on 2 of them and Owner B is listed on 3, I want it displayed as [Owner A, X, 2] and [Owner B, X, 3] in table 2.
Same goes for the other fields, which obviously adds more complexityWithin those calculations I also need to calculate the Start and end date for table 2. Using the last example, if one entry of Owner A's service X has the early start date and the other entry has the later end date, those dates need to be displayed in the Start and end for table 2 (should I use Rank here?)
I need to create a string of numbers separated by semicolons that shows how many resources are working on a given week after the start date
Example:I have 3 resources on a projectResource 1: 12/31/2012-1/27/2013 (Week 1-4 of our calendar)Resource 2: 1/7/2013-1/27/2013 (Week 2-4)Resource 3: 1/7/2013-1/27/2013 (Week 2-4)tblGRFM.Start will equal 12/31/2012 and tblGRFM.end will equal 1/27/2013Cadence should be equal to "1;3;3;3" to indicate that one resource will be working the project the first week, and three resources will be working the project for the next three weeks.
I've got a query that returns the data I need. I want to put the query in a stored procedure such that, when the SP runs I get a pipe delimited text file on disk. I don't really want to mess with SSIS, etc. Is there a Q&D way to do this?
Can someone demonstrate a SIMPLE way to do this that does not requireadditional functions or stored procedures to be created? Lets say Iwant to execute the following simple query - "select * from clients" -and save the results to a text file, we will assume c: esults.txtHow can I do this in one step?
Hey all, i'm making the pages meta keywords on my site dynamic, and i was wondering is there is a string, for example "Dell 17" Monitor Brand New", that would split it into each word for the meta keywords. example "Dell, 17", Monitor, Brand, New" (and possibly to not put a comma on the last word?)
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!
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.
When I send my query results to a file in SQL Server Management Studio, how come I'm seeing the following in Notepad++? FH TEST "FH" which I thought should be in a CHAR(2) data column is there but "TEST" seems to start in Column 6...not column 3 as I would have expected. I was expecting... FHTEST.