Showing posts with label export. Show all posts
Showing posts with label export. Show all posts

Wednesday, March 21, 2012

Force to date format MMDDYY

My sql :

SELECT....., date_ of_ shipment,.....

FROM......

WHERE.....

ORDER BY....

After that it will export to excel.

My problem: Some times I get a column of mixing date format MMDDYY and number.?


I have to format the whole excel column to get all date format.

My question: How can I write sql so it force the the result to be date format MMDDYY in excel? Where this clause in sql (where clause ?)

Thanks
Daniel

Code Snippet

select convert(varchar(8), getdate(), 1)

OR

select replace(convert(varchar(8), getdate(), 1), '/', '')

Depending on whether you want the slash separators or not.

Use code 101 instead of 1 in the Convert if you want 4 digit years.

|||

If my column name is date_of _shipment

Select convert (varchar(8), date_of_shipment,1) ?

Thnks

Daniel

|||

Right.

It will also lose it's name, so you may want to re-alias it.

Code Snippet

Select convert (varchar(8), date_of_shipment,1) AS date_of_shipment

|||

Thanks a millions. Look like it work great for what ever my excel column format.

Daniel

|||

I may need hour: min: second too

How about MMDDYYYYHHMMSS ?


Thanks
Daniel

force pdf to one page

Hi everyone,
I wanted to know when you export to a pdf if there is anyway to force the pdf to go from 2 pages to 1. Are there any parameter i might be able to pass?
thanks to all who answers the questionTry setting the rc:PageHeight property on the URL.
--
My employer's lawyers require me to say:
"This posting is provided 'AS IS' with no warranties, and confers no
rights."
"j-man" <j-man@.discussions.microsoft.com> wrote in message
news:0D6875DA-FF61-4A83-8E60-84AEDFD74B12@.microsoft.com...
> Hi everyone,
> I wanted to know when you export to a pdf if there is anyway to force the
pdf to go from 2 pages to 1. Are there any parameter i might be able to
pass?
> thanks to all who answers the question

Monday, March 19, 2012

Force Excel Column type when exporting from SSRS

Hi all,

I have a tricky behavior here. I have a column in my report which contains alphanumeric codes. When I have a code like 17E001 and I export the report to Excel, excel kindly shows that alphanumeric code to 1+E7 and the value of the column is changed to 1700 which is defintly not what I want.

So I was wondering if there is any way to force the column types when exporting from SSRS?

Sbastien.

By the way if there is a way to force all columns to be formated as Text that will do for me as the excel reports are only used to process data using SSIS.

Friday, March 9, 2012

For XML Fields Missing

SQL Server 2000 Enterprise Edition SP3a

Windows 2003 Enterprise Edition

I am trying to export a subset of a table to XML (using the where clause) and I am not getting all fields exported. I have tried using Auto, Raw, and Explicit and they all omit these fields. Here is my schema:

CREATE TABLE [dbo].[TableName] (
[TableID] [uniqueidentifier] NOT NULL ,
[Field01] [char] (6) NOT NULL ,
[Field02] [char] (4) NOT NULL ,
[Field03] [int] NOT NULL ,
[Field04] [varchar] (50) NOT NULL ,
[Field05] [char] (4) NULL ,
[Field06] [smalldatetime] NOT NULL ,
[Field07] [smallint] NULL ,
[Field08] [tinyint] NULL ,
[Field09] [tinyint] NULL ,
[Field10] [tinyint] NULL ,
[Field11] [smalldatetime] NULL ,
[Field12] [smalldatetime] NULL ,
[Field13] [money] NULL ,
[Field14] [money] NULL ,
[Field15] [smalldatetime] NULL ,
[Field16] [varchar] (50) ,
[Field17] [money] NULL ,
[Field18] [money] NULL ,
[Field19] [bit] NULL
) ON [PRIMARY]

When the XML is generated, I am not getting Field07, Field08, Field09, Field10, Field12, Field13, Field14, Field15, and Field16.

Here is my query:

CREATE PROCEDURE dbasp_get_TableData

(@.TableID uniqueidentifier) AS

SELECT
TableID, Field01, Field02, Field03, Field04, Field05, Field06, Field07,
Field08, Field09, Field10, Field11, Field12,
Field13, Field14, Field15, Field16,
Field17, Field18, Field19

FROM database.dbo.TableName

WHERE tableid = @.TableID

FOR XML AUTO, ELEMENTS

I still get the same problem if I do a Select * statement. All fields have data, so NULL cannot be an issue.

Please help!!! It does not make sense.

Thank you in advance.

I couldn't repro your problem. Following is my repro and result. Please provide your repro script and the version of your SQL 2000.

use tempdb
go

CREATE TABLE [dbo].[TableName] (
[TableID] [uniqueidentifier] NOT NULL ,
[Field01] [char] (6) NOT NULL ,
[Field02] [char] (4) NOT NULL ,
[Field03] [int] NOT NULL ,
[Field04] [varchar] (50) NOT NULL ,
[Field05] [char] (4) NULL ,
[Field06] [smalldatetime] NOT NULL ,
[Field07] [smallint] NULL ,
[Field08] [tinyint] NULL ,
[Field09] [tinyint] NULL ,
[Field10] [tinyint] NULL ,
[Field11] [smalldatetime] NULL ,
[Field12] [smalldatetime] NULL ,
[Field13] [money] NULL ,
[Field14] [money] NULL ,
[Field15] [smalldatetime] NULL ,
[Field16] [varchar] (50) ,
[Field17] [money] NULL ,
[Field18] [money] NULL ,
[Field19] [bit] NULL
) ON [PRIMARY]
go

insert TableName values(newid(), 'abc', 'def', 3, '04', '05', getdate(), 7, 8, 9, 10, getdate(), getdate(), 13.1, 14.5, getdate(), '16varchar', 17.3, 18.5, 1)
go

CREATE PROCEDURE dbasp_get_TableData

(@.TableID uniqueidentifier) AS

SELECT
TableID, Field01, Field02, Field03, Field04, Field05, Field06, Field07,
Field08, Field09, Field10, Field11, Field12,
Field13, Field14, Field15, Field16,
Field17, Field18, Field19

FROM tempdb.dbo.TableName

WHERE tableid = @.TableID

FOR XML AUTO, ELEMENTS
go

exec dbasp_get_TableData '9883A32F-3EF4-408F-BFEC-6540598FEBC1'

Result I get:

==================

<tempdb.dbo.TableName><TableID>9883A32F-3EF4-408F-BFEC-6540598FEBC1</TableID><Field01>abc </Field01><Field02>def </Field02><Field03>3</Field03><Field04>04</Field04><Field05>05 </Field05><Field06>2007-01-16T10:21:00</Field06><Field07>7</Field07><Field08>8</Field08><Field09>9</Field09><Field10>10</Field10><Field11>2007-01-16T10:21:00</Field11><Field12>2007-01-16T10:21:00</Field12><Field13>13.1000</Field13><Field14>14.5000</Field14><Field15>2007-01-16T10:21:00</Field15><Field16>16varchar</Field16><Field17>17.3000</Field17><Field18>18.5000</Field18><Field19>1</Field19></tempdb.dbo.TableName>

|||I did find where the problem was coming from. I reproduced the same result as your example. Somehow I had changed the GUID that was used when I knew that all fields were accounted for (not null) to a GUID that had several NULL values. Those fields don't get exported (not even the field names) when it is null. I have been able to get my code to work by utilizing ISNULL. Thank you for your time in helping me.

For XML Fields Missing

SQL Server 2000 Enterprise Edition SP3a

Windows 2003 Enterprise Edition

I am trying to export a subset of a table to XML (using the where clause) and I am not getting all fields exported. I have tried using Auto, Raw, and Explicit and they all omit these fields. Here is my schema:

CREATE TABLE [dbo].[TableName] (
[TableID] [uniqueidentifier] NOT NULL ,
[Field01] [char] (6) NOT NULL ,
[Field02] [char] (4) NOT NULL ,
[Field03] [int] NOT NULL ,
[Field04] [varchar] (50) NOT NULL ,
[Field05] [char] (4) NULL ,
[Field06] [smalldatetime] NOT NULL ,
[Field07] [smallint] NULL ,
[Field08] [tinyint] NULL ,
[Field09] [tinyint] NULL ,
[Field10] [tinyint] NULL ,
[Field11] [smalldatetime] NULL ,
[Field12] [smalldatetime] NULL ,
[Field13] [money] NULL ,
[Field14] [money] NULL ,
[Field15] [smalldatetime] NULL ,
[Field16] [varchar] (50) ,
[Field17] [money] NULL ,
[Field18] [money] NULL ,
[Field19] [bit] NULL
) ON [PRIMARY]

When the XML is generated, I am not getting Field07, Field08, Field09, Field10, Field12, Field13, Field14, Field15, and Field16.

Here is my query:

CREATE PROCEDURE dbasp_get_TableData

(@.TableID uniqueidentifier) AS

SELECT
TableID, Field01, Field02, Field03, Field04, Field05, Field06, Field07,
Field08, Field09, Field10, Field11, Field12,
Field13, Field14, Field15, Field16,
Field17, Field18, Field19

FROM database.dbo.TableName

WHERE tableid = @.TableID

FOR XML AUTO, ELEMENTS

I still get the same problem if I do a Select * statement. All fields have data, so NULL cannot be an issue.

Please help!!! It does not make sense.

Thank you in advance.

I couldn't repro your problem. Following is my repro and result. Please provide your repro script and the version of your SQL 2000.

use tempdb
go

CREATE TABLE [dbo].[TableName] (
[TableID] [uniqueidentifier] NOT NULL ,
[Field01] [char] (6) NOT NULL ,
[Field02] [char] (4) NOT NULL ,
[Field03] [int] NOT NULL ,
[Field04] [varchar] (50) NOT NULL ,
[Field05] [char] (4) NULL ,
[Field06] [smalldatetime] NOT NULL ,
[Field07] [smallint] NULL ,
[Field08] [tinyint] NULL ,
[Field09] [tinyint] NULL ,
[Field10] [tinyint] NULL ,
[Field11] [smalldatetime] NULL ,
[Field12] [smalldatetime] NULL ,
[Field13] [money] NULL ,
[Field14] [money] NULL ,
[Field15] [smalldatetime] NULL ,
[Field16] [varchar] (50) ,
[Field17] [money] NULL ,
[Field18] [money] NULL ,
[Field19] [bit] NULL
) ON [PRIMARY]
go

insert TableName values(newid(), 'abc', 'def', 3, '04', '05', getdate(), 7, 8, 9, 10, getdate(), getdate(), 13.1, 14.5, getdate(), '16varchar', 17.3, 18.5, 1)
go

CREATE PROCEDURE dbasp_get_TableData

(@.TableID uniqueidentifier) AS

SELECT
TableID, Field01, Field02, Field03, Field04, Field05, Field06, Field07,
Field08, Field09, Field10, Field11, Field12,
Field13, Field14, Field15, Field16,
Field17, Field18, Field19

FROM tempdb.dbo.TableName

WHERE tableid = @.TableID

FOR XML AUTO, ELEMENTS
go

exec dbasp_get_TableData '9883A32F-3EF4-408F-BFEC-6540598FEBC1'

Result I get:

==================

<tempdb.dbo.TableName><TableID>9883A32F-3EF4-408F-BFEC-6540598FEBC1</TableID><Field01>abc </Field01><Field02>def </Field02><Field03>3</Field03><Field04>04</Field04><Field05>05 </Field05><Field06>2007-01-16T10:21:00</Field06><Field07>7</Field07><Field08>8</Field08><Field09>9</Field09><Field10>10</Field10><Field11>2007-01-16T10:21:00</Field11><Field12>2007-01-16T10:21:00</Field12><Field13>13.1000</Field13><Field14>14.5000</Field14><Field15>2007-01-16T10:21:00</Field15><Field16>16varchar</Field16><Field17>17.3000</Field17><Field18>18.5000</Field18><Field19>1</Field19></tempdb.dbo.TableName>

|||I did find where the problem was coming from. I reproduced the same result as your example. Somehow I had changed the GUID that was used when I knew that all fields were accounted for (not null) to a GUID that had several NULL values. Those fields don't get exported (not even the field names) when it is null. I have been able to get my code to work by utilizing ISNULL. Thank you for your time in helping me.

Sunday, February 19, 2012

FOR EACH Loop to export files based on Header Record

Hey guys,,

Well im new at this SSIS stuff and i have something that i am trying to do, but cannot get it to work.. Ill try to explain, and if anyone can help me or point me in the right direction it would be much appriciated..

I have 2 tables, one header table. and one lines table. This is a one - to -many relationship.. ie 1 header, many lines.. This is a Order Header, and Order Lines table setup.. Order header has Order numbers and and email address field that link to the lines table by order number. I also have a view which links all this info together.

I would like to export a excel file (preferable named from the order number column - but that can come later) for each order number in the header table. The excel file will contain the details from the View that was created. I want this to loop through all the header records in the header table and create a excel file for each one..


Down the track i want to add a send mail task to this and pass the email address to a variable so i can use it in the send mail task.. But ill get the main part working first..

Anyhelp would be more than helpful.. I tried to set this up, but i am stuck on the enumerator part..

thanks again, scotty

I just created my first blog entry with something for you; let me know if it helps.

http://rafael-salas.blogspot.com/2006/12/import-header-line-tables-into-dynamic_22.html

http://rafael-salas.blogspot.com/2006/12/import-header-line-tables-_116683388696570741.html

|||

Thanks Rafael.. This is exactly what i wanted to do and you have described the process exactly

Much appriciated..

Merry xmas and have a happpy new year..

Thaks


Scotty