SQL Server 2008 :: DBMail Output Query Results As CSV With Headers But No Separator

Aug 25, 2015

If I use msdb..sp_send_dbmail or save query results as text (using sqlcmd) and include the column headers I get the dashed separator line.

e.g.

custID, name
------, ------
1,bob
2,jamesI would like this
custID, name
1, bob
2 ,james

I found this method [URL] ....

::
sqlcmd -E -S (local) -d myDB -W -w 1024 -s "," -i "SELECT * FROM tblCust" | findstr /V /C:- /B > C: emp.csv

Can the same result be achieved sending as attachment with dbmail?

EXEC msdb..sp_send_dbmail @attach_query_result_as_file = 1I don't want to have to add column names as part of the query

Change the query to return column headers in resultset
SELECT 'CustID' as f1, 'name' as f2
UNION ALL
SELECT CAST(CustID as Varchar(10)), name FROM tblCustand set

msdb..sp_send_dbmail @query_result_header = 0

View 0 Replies


ADVERTISEMENT

SQL Server 2008 :: Query Results Output Into CSV File To Use In VBA Macro

Jul 31, 2015

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.

-- Declare the variables
DECLARE @CMD VARCHAR(4000),
@DelCMD VARCHAR(4000),
@HEADERCMD VARCHAR(4000),
@Combine VARCHAR(4000),
@Path VARCHAR(4000),
@COLUMNS VARCHAR(4000)

[Code] ...

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^

[Code] ....

View 1 Replies View Related

SQL Server 2008 :: Export Output Into CSV File As A Report With Column Headers?

Aug 20, 2015

I have a table which has few columns as Numeric value. I need to export the output into a csv file as a report with column headers. I have used bcp command. Here column name and Column Header name is the same. The BCP query which i have used is Below

bcp "SelectCompanyCode,MonthId,ActualityCode,CompanyCounterpartCode,LocalProductCode,LocalCustomerBillTo,
DestinationCountryCode,LocalCostCenterCode,LocalGLAccountCode,LocalProjectCode,TXCurrencyCode,
TXAmountYTD,LocalCurrencyCode,LocalAmountYTD,SourceSystemFromTable(nolock)" queryout D: est.csv -c -t ";" -r -S -T

Is there any way to export bcp with header or any other command to generate the csv file.

View 1 Replies View Related

Removing Headers From Query Analyzer Output

Mar 14, 2001

Hi. How can I display output from a simple SQL query in Query Analyzer so that the column heading/broken underline
appearing above the column values is not displayed? Something akin to "set heading off".

Thanks

View 1 Replies View Related

SQL Server 2008 :: DBmail HTML Body Size Limit

Nov 4, 2015

When sending an email in HTML format, shouldn't this allow for 2gb of data? Mine is getting truncated after 4000 characters.

@body NVARCHAR(MAX) = NULL,

EXEC msdb.dbo.sp_send_dbmail
@recipients='someone@some.com',
@reply_to='someone'
@from_address='someone@here.com>',
@profile_name = 'profilename',
@body_format = 'HTML',
@body = 'lots of data'

View 2 Replies View Related

Sql Server 2005 Sql Statment To Output Query Results To A File

Jan 21, 2008



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?

Thanks,
Mike

View 1 Replies View Related

Get DBMail Output?

May 30, 2013

With Query Anylyser, I am sending mails with DBMail successfully. Each time mail is sent, bottom half window messages tab shows

"Mail (Id: 30242) queued."

Is there any way to capture Mail (Id: 30242) and update the same in a table?

View 1 Replies View Related

SQL Server 2008 :: Query To Show XML Output For Hierarchical Data?

Mar 10, 2015

selecting table data in hierarchical XML .

Here is the sample table DDL and data

Declare @continents Table
(
id int identity (1,1)
,continent_id int
,continent_Name varchar(100)
,continent_surface_area varchar(100)
,country_id int

[code]....

View 8 Replies View Related

SQL Server 2008 :: Query Plan Output List (IsBaseRow)

May 6, 2015

Looking at an execution plan today I noticed something I've not seen before. The plan includes a non clustered index seek, followed by a RID lookup on the heap. The output list for the index seek contains the expected "Bmk" column (in this case "Bmk1473"), but also includes "IsBaseRow1475". This isn't a column from the table.

View 3 Replies View Related

SQL Server 2008 :: Storing Dynamic Query Output In Temp Table

Apr 6, 2015

I have a dynamic sql which uses Pivot and returns "technically" variable no. of columns.

Is there a way to store the dynamic sql's output in to a temp table? I don't want to create a temp table with the structure of the output and limit no. of columns hence changing the SP every time I get new Pivot column!!

View 3 Replies View Related

SQL Server 2008 :: Send Emails To Individuals In Query Results And Extra?

Jul 15, 2015

I have a set of results based on a query that displays a learner, their workplace assessor and both their email addresses.

I want to send a standard request email (using db_mail) to each learner's email address which specifies who their individual assessor is and their current employer. One per learner.
I then want to email each assessor and in this email detail their learners (and their employer details) that I have emailed the request too.

View 1 Replies View Related

SQL Server 2008 :: Elegant Way For Returning All Results When Subquery Returns No Results?

Mar 25, 2015

I have four tables: Customer (CustomerId INT, CountyId INT), County (CountyId INT), Search(SearchId INT), and SearchCriteria (SearchCriteriaId INT, SearchId INT, CountyId INT, [others not related to this]).

I want to search Customer based off of the Search record, which could have multiple SearchCriteria records. However, if there aren't any SearchCriteria records with CountyId populated for a given Search, I want it to assume to get all Customer records, regardless of CountyId.

Right now, I'm doing it this way.

DECLARE @SearchId INT = 100
SELECT * FROM Customer WHERE
CountyId IN
(
SELECT CASE WHEN EXISTS(SELECT CountyId FROM SearchCriteria WHERE SearchId = @SearchId)
THEN SearchCriteria.CountyId

[Code] .....

This works; it just seems cludgy. Is there a more elegant way to do this?

View 4 Replies View Related

SQL Server 2008 :: How To Pivot Unknown Number Of Rows To Columns Using Data As Column Headers

Sep 10, 2015

I have a single table that consist of 4 columns. Entity, ParamName, ParamsValue and ParamiValue. This table stores normalized Late Fee related parameters for apartments. The Entity field contains a code that identifies the apartment complex. The ParamName in a textual field that contains the name of the parameter that the other 2 fields define the value for; ParamsValue and ParamiValue. If the Late Fee parameter (as named in ParamName is something numerical then the value for that parameter can be found in ParamiValue else its in ParamsValue.

I don't know if 'Pivot' is the correct term to use for describing what I am trying to do because I've looked at the Pivot examples and I don't see how that will work for this. Using the Table and data as provided below, how would I construct a query so that I get 1 row per Entity in which the columns are the ParamsValue or ParamiValue for the ParamName listed in the column header (for the query)?

Below is the DDL to create the table and populate it.

USE [DBA_UTIL]
CREATE TABLE [dbo].[PARAMEXAMPLE](
[Entity] [varchar](16) NULL,

[Code]....

View 4 Replies View Related

Output Results Of Query To A Txt File

Apr 3, 2001

I have come across manual queries being run daily and the results saved to a txt file on the network.

I basically want to set run these up a stored procedure and set up as a scheduled task to run daily.

Does anyone know if you can automatically save the results of a query/stored procedure to a text file on a network??

Many Thanks..

View 1 Replies View Related

Stored Procedure | Selects Some Data |query The Results It Created And Output

Dec 2, 2005

I can create 1 view of a database then use that views results to query

but i want do this with a stored procedure
pass some data to it, so it selects some data

query the results it created and output this data.

ie


pass 2 values to the procedure
(
@FirstValue int,
@secondValue int output

)


select from a database with the firstpassed value

Select *
From TableName
Where ID = @FirstValue

Then
using the results from the above select

Select *
From theResultsOfAbove
Where ID = @SecondValue

any ideas would be fabo !

View 6 Replies View Related

Reporting Services :: Tablix Headers Not Repeating In SSRS 2008

Nov 3, 2008

I have created a new report & add a table to it. When I select "Tablix Properties" and check on Columns Headers -> "Repeat Cheader columns on each page" the header columns do not repeat on each page. I also tried "Repeat header rows on each page". "Add page break before" seems to work ok. I am using VS 2008 9.0.30729.1 SP..I also tried deploying but it still does not work on the deployed version.

View 69 Replies View Related

SQL Server 2008 :: Data Output In XML

Feb 22, 2015

I have below two table and i want ot generate the xml out put as mentioned below.

create table Candidates(eno int,ResumeText varchar(30), Email varchar(30),Active varchar(30),postalcode varchar(30),country int)
insert into Candidates
select 1,'Test','ee@ee.com','Active yes','888888',2
union all
select 2,'Test','ee@ee.com','Active yes','888888',6

[code]...

View 2 Replies View Related

SQL Server 2008 :: How To Remove Spaces From Output

Jun 23, 2015

When I save my output (from a query I ran) to a text file, there seems to be rows of spaces. Is there a way i can just kill off any spaces at the end of my query? Like rtrim or something?

View 9 Replies View Related

SQL Server 2008 :: Batch Archiving With OUTPUT

Oct 13, 2015

I have to set up archiving of some pretty large tables (125M+ rows) and I'm trying to figure out the best way to do it.

I've been using OUTPUT into, something like this:

delete top (100000) a
output deleted.RecordID
into dbo.RecordsArchive (RecordID)
from dbo.Records

It's difficult to tell if it sub-optimal code or just sheer volume, but any performance penalty using OUTPUT into in this way? or is it advantageous to insert the records to the archive first, and then delete them in two separate operations?

View 0 Replies View Related

SQL Server 2008 :: How To Get Rid Of NULL In Results From Case When

Sep 21, 2015

I'm trying to get a result set without the NULLs. Here is the code I'm using. I'd like the results to look like:

17285204 90471 090471
17285204 90715 090715
17285204 99396 099396
17285204 99420 099420
17285204 90471 090471
17285204 NULL G0444

create table #Test
(
AppNum varchar(10),
CPT varchar(10),
src char(1)
)
insert into #Test(AppNum, CPT, src) values('17285204','090471','b')

[Code] ...

View 5 Replies View Related

SQL Server 2012 :: Run Script Within A Table / String And Output Results To File?

Sep 21, 2015

I have been given a request at work that requires us to run the SQL scripts that are held in a report configuration table and output the results as .csv or.xls files in a desired folder with a file name that is also specified within the report config table.

An example of the table is as per script below with column A being the desired file name to be created and Column B contains the script that will be executed.

Ideally I require a script that i can drop into a Stored Proc that will run down each row in the table and export and create each rows results as a separate file in a desired folder.

------------------------------------------------------------------------------------------
-----SAMPLE TABLE SCRIPT -----------------------------------------------------------
------------------------------------------------------------------------------------------
/****** Object: Table [dbo].[Test_Table_PS] Script Date: 21/09/2015 09:14:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test_Table_PS](
[File_Name] [nvarchar](100) NULL,

[Code] ....

View 7 Replies View Related

SQL Server 2008 :: How To Get Output Based On Sequential Number

Feb 13, 2015

The below data come from table table1. Instead of below result Ex1: I need output similar to the ex2.

Ex1:

CaseNumberStart CaseNumberEndExported
15000013150000131
15000014150000141
15000504150005041
15000505150005051

Ex2:

CaseNumberStart CaseNumberEndExported
15000013150000142
15000504150005052

How to get the result similar to Ex2, instead of Ex1. (ie., case-number is in sequential order then no need to break), And it should suit large dataset, I will finetune, if any performance issue.

View 1 Replies View Related

SQL Server 2008 :: SSMS Truncating PowerShell Output?

Jun 3, 2015

When I execute the following command, I get the output truncated to 79 characters, including three dots (as an ellipsis, I suppose).

EXEC master..xp_cmdshell 'powershell.exe "Get-ChildItem D:Databazepaleontologieprilohyverejneg -filter g417*.* -recurse | select Fullname | out-string -width 255"'When I execute the core command directly in Powershell, whether the text or ISE version, it works correctly, with or without the out-string -width command.

Get-ChildItem D:Databazepaleontologieprilohyverejneg -filter g417*.* -recurse | select Fullname | out-string -width 255What does it take to get SSMS to not truncate my output strings?

View 6 Replies View Related

SQL Server 2008 :: Display Output Of Table In Given Format?

Aug 19, 2015

I have a table Test123 having three column EmpID,AttribName,AttribValue.

run the below query to generate table structure and data.

Create Table Test123(EmpID int,AttribName varchar(50),AttribValue varchar(50))

insert into Test123 values(1,'Name','X')
insert into Test123 values(1,'Age',50)
insert into Test123 values(1,'Salary',1000)
insert into Test123 values(2,'Name','Y')
insert into Test123 values(2,'Age',30)
insert into Test123 values(2,'Salary',2000)
insert into Test123 values(3,'Name','Z')
insert into Test123 values(3,'Age',35)
insert into Test123 values(3,'Salary','One Hundred')

And I want output in below format.

AttributeValueType
=================
AGE | NUMERIC
NAME | ALPHABET
SALARY | ALPHANUMERIC
==================

View 6 Replies View Related

SQL Server 2008 :: How To Hide Criteria In Search Results

May 28, 2015

Say I want to search for a range of account numbers but only which are active. After I set my field for A (active) this field shows in my results, I dont want it to.

In Access you can easily just uncheck that field in design view, but how do I do it in sql?

View 4 Replies View Related

SQL Server 2008 :: Unable To Open Step Output File

Aug 27, 2013

I am running sql script inside job.But sql is not saving the results in the file which i specified('Unable to open Step output file'). I tried same thing on different server, it works fine.Both are are 2008 R2.Is there any server level setting that i have to look at.On both servers i logged in as sal. Why is it working on server1 ,but not on server2?

View 6 Replies View Related

SQL Server 2008 :: Cleanup History Has Extra Output Message

Apr 16, 2015

Oldest Day till I want to Purge[30 days of Old Data] : 03-17-2015

Running Cleanuphistory Procedure On Server:

NO of records are qualifying for deletion:0

Deleted Sysmail MAil Items, Old history: 1
Deleted Sysmail Log Old history: 1
0 history entries purged. <<<<<<< ----------------------- [HOW IT IS COMING ?? ??]
Deleted SQL JOB Old HISTORY: 1

*** END OF PROCEDURE. ***

[Code] .....

View 6 Replies View Related

SQL Server 2008 :: Display List Of Indexes - Add Database Name In Results

Apr 6, 2015

I written a proc to display the list of Indexes But I needed to print the database where the objects do belong to. How I should write the Dynamic script to add the database Id? I thought to use derived table kind of stuff, but unable to find a solution.

ALTER PROC [dbo].[USP_INDEXCHECK]
AS
DECLARE @sql NVARCHAR(max)
DECLARE @DB VARCHAR(max)
DECLARE databasecursor CURSOR FOR

[Code] .....

View 2 Replies View Related

SQL Server 2008 :: Select Statements To Output Files With Proper Datestamp

Jun 11, 2015

I have few complex queries and I want to extract the output of results to all different dateformatted output files.

How to write the queries?

I know BCP is a solution but any other effective way to implement it?

View 2 Replies View Related

SQL Server 2008 :: Stored Procedure Script Output To Text File

Apr 29, 2009

I am having a Stored Procedure Or SQL Script to be attached to Job Scheduler. When this Stored procedure executes it generates some output text. I need to store this output to text file when ever this store Procedure (or) SQL Script executed by job Scheduler.

View 9 Replies View Related

SQL Server 2008 :: Create All Procedures Located In A Folder One By One And Saving Output File

May 15, 2015

I am asked to create 100 procedures to a database. Any best way to create them in a database one by one by calling the files and saving the execution output files in a folder?

View 9 Replies View Related

How Can I Use Comma Like A Decimal Separator In Sql Server Express?

Sep 11, 2006

I need HELP

"update product set price='1,99' where cod='001'"

I need COMMA... not DOT

In oracle i use "alter session set language='Brazil'"... but... in SQL SERVER???

View 3 Replies View Related

Report Headers Vs Page Headers

Feb 8, 2007

Hi, this is probably a simple question but I just can't figure it out. I'm using SQL Server Reporting Services 2005 sp1.

I'm trying to design a report that displays a particular embedded image on the first page, and then a different one on every subsequent page. I.e full, fancy company logo on the first page, and a trimmed down version on every other. In Crystal, I would have simply used the Report Header and Page Header sections to achieve this - easy.

However, in SQL Reporting Services, there is only a Page Header section - therefore whatever I place in the Page Header shows on every page. Now, I know how to stop it displaying on the first page, but I don't know how to display the other image instead.

I read in a support forum that it is possible to do this by "placing report items above or below your data regions" but I can't get it to work.

Grateful for any assistance.

Matt

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved