A table has a datetime column, which contains dates only (no time part). In
EM, the dates look like 5/10/2007. After exporting the table to a CSV file
using All Tasks->Export Data... the dates look like 2007-05-10 00:00:00.
How can I export the dates in the same format they appear in the EM, that is
5/10/2007? At least I need that the dates appear in the CSV file without the
time part.
Thank you.
Check BOL for the CONVERT function. I believe 101 is the one you are
looking for.
TheSQLGuru
President
Indicium Resources, Inc.
"Vik" <viktorum@.==yahoo.com==> wrote in message
news:%2307zUA0kHHA.3264@.TK2MSFTNGP04.phx.gbl...
>A table has a datetime column, which contains dates only (no time part). In
>EM, the dates look like 5/10/2007. After exporting the table to a CSV file
>using All Tasks->Export Data... the dates look like 2007-05-10 00:00:00.
> How can I export the dates in the same format they appear in the EM, that
> is 5/10/2007? At least I need that the dates appear in the CSV file
> without the time part.
> Thank you.
>
>
Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts
Tuesday, March 27, 2012
Friday, March 9, 2012
Expected Formatted Results?
Hi All,
I am kindly seeking for help.
I have a table(MyTable) which is defined as (date datetime, ID char (10), and R, P,M,D&Y are all float) and the layout is as following:
Date ID R P M D... Y
1/1/90 A 1 2 3 4... 5
1/2/90 A 2 3 4 5... 1
...
2/11/05 A 3 4 5 6... 2
1/1/90 B 1 2 3 4... 5
1/2/90 B 2 3 4 5... 1
...
2/11/05 B 3 4 5 6... 2
...
The expected query results look like: ( this results from Date, ID and R fields)
Date A B
1/1/90 1 1
1/2/90 2 2
...
2/11/05 3 3
The SQL I wrote:
select date, ID,
A=sum(case when ID=A then R else 0 end),
B=sum(case when id=B then R else 0 end)
from MyTable
Group by date
I would also like to get another set of results with the same format but from date,ID and P fields:
Date A B
1/1/90 2 2
1/2/90 3 3
...
2/11/05 4 4
select date, ID,
A=sum(case when ID=A then P else 0 end),
B=sum(case when id=B then P else 0 end)
from MyTable
Group by date
The problem with that is if I have thousands of ID in MyTable I have to "hard code" thousands times and the same problem with the fields/columns. Is there any easier way to do this?
I also would like to insert the results into a table/view which will be refreshed whenever MyTable gets updated.
Any suggestion/comments are highly appreciated!
shiparsonsFor the moment you have to do it this way, unless you want to get into hairy dynamic SQL.
And anyway, if you do not hard-code the column names in your crosstabs then good luck creating any reports based upon them (Crystal, Access, or anything else). Reporting applications tend to require advance knowledge of the data layout they use...|||Not because I do not trust your comments...I am not sure if I know SQL well enough to make a judgement. Is there another way to go around? Could you please elaberate "hairy Dynamic SQL"?
Many thanks,
shiparsons|||I agree with blindman, this problem is practically impossible to solve on the server. However, there are many, relatively simple solutions to this problem on the client side.
Depending on what tool you choose to use, the wording and methods are slightly different. Excel has pivot tables (http://www.microsoft.com/technet/prodtechnol/office/office2000/support/helpofc.mspx), MS-Access has crosstab reports (http://support.microsoft.com/default.aspx?scid=kb;en-us;328320), etc. Most client analysis tools support this type of activity in some way.
-PatP|||Hairy dynamic SQL, meaning you will have to access the system tables or SCHEMA tables to locate the columns for your table, and then loop through each one of them constructing your SQL statement as a string before executing it.
I am kindly seeking for help.
I have a table(MyTable) which is defined as (date datetime, ID char (10), and R, P,M,D&Y are all float) and the layout is as following:
Date ID R P M D... Y
1/1/90 A 1 2 3 4... 5
1/2/90 A 2 3 4 5... 1
...
2/11/05 A 3 4 5 6... 2
1/1/90 B 1 2 3 4... 5
1/2/90 B 2 3 4 5... 1
...
2/11/05 B 3 4 5 6... 2
...
The expected query results look like: ( this results from Date, ID and R fields)
Date A B
1/1/90 1 1
1/2/90 2 2
...
2/11/05 3 3
The SQL I wrote:
select date, ID,
A=sum(case when ID=A then R else 0 end),
B=sum(case when id=B then R else 0 end)
from MyTable
Group by date
I would also like to get another set of results with the same format but from date,ID and P fields:
Date A B
1/1/90 2 2
1/2/90 3 3
...
2/11/05 4 4
select date, ID,
A=sum(case when ID=A then P else 0 end),
B=sum(case when id=B then P else 0 end)
from MyTable
Group by date
The problem with that is if I have thousands of ID in MyTable I have to "hard code" thousands times and the same problem with the fields/columns. Is there any easier way to do this?
I also would like to insert the results into a table/view which will be refreshed whenever MyTable gets updated.
Any suggestion/comments are highly appreciated!
shiparsonsFor the moment you have to do it this way, unless you want to get into hairy dynamic SQL.
And anyway, if you do not hard-code the column names in your crosstabs then good luck creating any reports based upon them (Crystal, Access, or anything else). Reporting applications tend to require advance knowledge of the data layout they use...|||Not because I do not trust your comments...I am not sure if I know SQL well enough to make a judgement. Is there another way to go around? Could you please elaberate "hairy Dynamic SQL"?
Many thanks,
shiparsons|||I agree with blindman, this problem is practically impossible to solve on the server. However, there are many, relatively simple solutions to this problem on the client side.
Depending on what tool you choose to use, the wording and methods are slightly different. Excel has pivot tables (http://www.microsoft.com/technet/prodtechnol/office/office2000/support/helpofc.mspx), MS-Access has crosstab reports (http://support.microsoft.com/default.aspx?scid=kb;en-us;328320), etc. Most client analysis tools support this type of activity in some way.
-PatP|||Hairy dynamic SQL, meaning you will have to access the system tables or SCHEMA tables to locate the columns for your table, and then loop through each one of them constructing your SQL statement as a string before executing it.
Sunday, February 19, 2012
Execution snapshots and datetime
Hello, I need some help with a problem i'm encountering:
I have a parameter named "startDate" defined in a report. The data type for
this parameter is DateTime and the default value I set in the report is
Non-queried with =Now() as the value. This value is sent to a SQL sProc.
When I run the report through my ASP.net page, it displays nicely.
I'm trying to use execution snapshots for this report with nightly email
subscriptions because the report returns large amounts of data and we can't
have it process the report at peak business hours. However when I try to set
up execution snapshots with this report, and set the startDate parameter
default value to =Now() in Report Manager, I get the error of "The property
of report parameter startDate doesn't have the expected type."
So then I changed the data type for parameter startDate to String and set
the value to =Now() in Report manager. At least now it takes the value. But
when trying to setup the snapshot again, I receive "Syntax error converting
datetime from character string" even though I use the convert function in
the SQL sProc. I need the snapshot to generate reports on a per week basis
and I can't hardcode a date in the parameter field like "9/9/2004". It has
to be =Now() so it can generate a snapshot per week automatically with that
weeks data. I've tried everything and i can't get it to work. Is there
anyway I can get Now() or DateAdd() to work in a datetime (or string if I
have to) field using execution snapshots? thank youYou cannot change an expression-based default value once the report is
published on the report server. When you type in =Now, then it is
interpreted as string "=Now" and *not* as expression.
You will need delete the report from report server, load the RDL file in
report designer, set the expression-based default value there (e.g. =Now or
=Today) and then republish the report to the report server.
Then you should be able to create execution snapshots without any issues.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mark" <idroppeddabomb@.hotmail.com> wrote in message
news:eq5E2bplEHA.1652@.TK2MSFTNGP09.phx.gbl...
> Hello, I need some help with a problem i'm encountering:
> I have a parameter named "startDate" defined in a report. The data type
for
> this parameter is DateTime and the default value I set in the report is
> Non-queried with =Now() as the value. This value is sent to a SQL sProc.
> When I run the report through my ASP.net page, it displays nicely.
> I'm trying to use execution snapshots for this report with nightly email
> subscriptions because the report returns large amounts of data and we
can't
> have it process the report at peak business hours. However when I try to
set
> up execution snapshots with this report, and set the startDate parameter
> default value to =Now() in Report Manager, I get the error of "The
property
> of report parameter startDate doesn't have the expected type."
> So then I changed the data type for parameter startDate to String and set
> the value to =Now() in Report manager. At least now it takes the value.
But
> when trying to setup the snapshot again, I receive "Syntax error
converting
> datetime from character string" even though I use the convert function in
> the SQL sProc. I need the snapshot to generate reports on a per week basis
> and I can't hardcode a date in the parameter field like "9/9/2004". It has
> to be =Now() so it can generate a snapshot per week automatically with
that
> weeks data. I've tried everything and i can't get it to work. Is there
> anyway I can get Now() or DateAdd() to work in a datetime (or string if I
> have to) field using execution snapshots? thank you
>
I have a parameter named "startDate" defined in a report. The data type for
this parameter is DateTime and the default value I set in the report is
Non-queried with =Now() as the value. This value is sent to a SQL sProc.
When I run the report through my ASP.net page, it displays nicely.
I'm trying to use execution snapshots for this report with nightly email
subscriptions because the report returns large amounts of data and we can't
have it process the report at peak business hours. However when I try to set
up execution snapshots with this report, and set the startDate parameter
default value to =Now() in Report Manager, I get the error of "The property
of report parameter startDate doesn't have the expected type."
So then I changed the data type for parameter startDate to String and set
the value to =Now() in Report manager. At least now it takes the value. But
when trying to setup the snapshot again, I receive "Syntax error converting
datetime from character string" even though I use the convert function in
the SQL sProc. I need the snapshot to generate reports on a per week basis
and I can't hardcode a date in the parameter field like "9/9/2004". It has
to be =Now() so it can generate a snapshot per week automatically with that
weeks data. I've tried everything and i can't get it to work. Is there
anyway I can get Now() or DateAdd() to work in a datetime (or string if I
have to) field using execution snapshots? thank youYou cannot change an expression-based default value once the report is
published on the report server. When you type in =Now, then it is
interpreted as string "=Now" and *not* as expression.
You will need delete the report from report server, load the RDL file in
report designer, set the expression-based default value there (e.g. =Now or
=Today) and then republish the report to the report server.
Then you should be able to create execution snapshots without any issues.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mark" <idroppeddabomb@.hotmail.com> wrote in message
news:eq5E2bplEHA.1652@.TK2MSFTNGP09.phx.gbl...
> Hello, I need some help with a problem i'm encountering:
> I have a parameter named "startDate" defined in a report. The data type
for
> this parameter is DateTime and the default value I set in the report is
> Non-queried with =Now() as the value. This value is sent to a SQL sProc.
> When I run the report through my ASP.net page, it displays nicely.
> I'm trying to use execution snapshots for this report with nightly email
> subscriptions because the report returns large amounts of data and we
can't
> have it process the report at peak business hours. However when I try to
set
> up execution snapshots with this report, and set the startDate parameter
> default value to =Now() in Report Manager, I get the error of "The
property
> of report parameter startDate doesn't have the expected type."
> So then I changed the data type for parameter startDate to String and set
> the value to =Now() in Report manager. At least now it takes the value.
But
> when trying to setup the snapshot again, I receive "Syntax error
converting
> datetime from character string" even though I use the convert function in
> the SQL sProc. I need the snapshot to generate reports on a per week basis
> and I can't hardcode a date in the parameter field like "9/9/2004". It has
> to be =Now() so it can generate a snapshot per week automatically with
that
> weeks data. I've tried everything and i can't get it to work. Is there
> anyway I can get Now() or DateAdd() to work in a datetime (or string if I
> have to) field using execution snapshots? thank you
>
Subscribe to:
Posts (Atom)