Showing posts with label newbie. Show all posts
Showing posts with label newbie. Show all posts

Thursday, March 29, 2012

date range query not returning anticipated results

Newbie question. When I query a field (datetime datatype) the results appear as if it were looking at text. There is no time data stored in the field.
Query:
select startdate
from auditlog
where startdate between '6/18/2004' and '6/20/2004'
I get results like this, with dates outside the specified range:
6/18/2004
6/18/2004
6/2/2004
6/19/2003
6/19/2003
6/2/2004
6/2/2004
6/2/2004
Any suggestions?
Any difference if you do it this way?
select startdate
from auditlog
where startdate between '20040618' and '20040620'
Andrew J. Kelly SQL MVP
"Yayahim" <Yayahim@.discussions.microsoft.com> wrote in message
news:C9A1AD19-40FE-42CE-BAC1-C69353F5F458@.microsoft.com...
> Newbie question. When I query a field (datetime datatype) the results
appear as if it were looking at text. There is no time data stored in the
field.
> Query:
> select startdate
> from auditlog
> where startdate between '6/18/2004' and '6/20/2004'
> I get results like this, with dates outside the specified range:
> 6/18/2004
> 6/18/2004
> 6/2/2004
> 6/19/2003
> 6/19/2003
> 6/2/2004
> 6/2/2004
> 6/2/2004
> Any suggestions?
|||Any difference if you do it this way?
select startdate
from auditlog
where startdate between '20040618' and '20040620'
Andrew J. Kelly SQL MVP
"Yayahim" <Yayahim@.discussions.microsoft.com> wrote in message
news:C9A1AD19-40FE-42CE-BAC1-C69353F5F458@.microsoft.com...
> Newbie question. When I query a field (datetime datatype) the results
appear as if it were looking at text. There is no time data stored in the
field.
> Query:
> select startdate
> from auditlog
> where startdate between '6/18/2004' and '6/20/2004'
> I get results like this, with dates outside the specified range:
> 6/18/2004
> 6/18/2004
> 6/2/2004
> 6/19/2003
> 6/19/2003
> 6/2/2004
> 6/2/2004
> 6/2/2004
> Any suggestions?
|||Are you using SQL Server 7? I don't think SQL Server 2000 will do this,
but in any case, try
where startdate between cast('20040618' as datetime) and cast('20040620'
as datetime)
Steve Kass
Drew University
Yayahim wrote:

>Newbie question. When I query a field (datetime datatype) the results appear as if it were looking at text. There is no time data stored in the field.
>Query:
>select startdate
>from auditlog
>where startdate between '6/18/2004' and '6/20/2004'
>I get results like this, with dates outside the specified range:
>6/18/2004
>6/18/2004
>6/2/2004
>6/19/2003
>6/19/2003
>6/2/2004
>6/2/2004
>6/2/2004
>Any suggestions?
>
|||Are you using SQL Server 7? I don't think SQL Server 2000 will do this,
but in any case, try
where startdate between cast('20040618' as datetime) and cast('20040620'
as datetime)
Steve Kass
Drew University
Yayahim wrote:

>Newbie question. When I query a field (datetime datatype) the results appear as if it were looking at text. There is no time data stored in the field.
>Query:
>select startdate
>from auditlog
>where startdate between '6/18/2004' and '6/20/2004'
>I get results like this, with dates outside the specified range:
>6/18/2004
>6/18/2004
>6/2/2004
>6/19/2003
>6/19/2003
>6/2/2004
>6/2/2004
>6/2/2004
>Any suggestions?
>

Sunday, March 25, 2012

Date Picker control returning date is US format

SQL 2005 SP2 + hotfix build 3152
I'm a newbie to reporting services and I am just learning and testing at the
moment. I am based in the UK.
I have set up a report with two parameters that are both dates.
When running the report in the IDE or http://ServerName/Reports dates picked
from the calendar control return as DD/MM/YYYY
When I run the report through http://Servername/ReportServer the date is
returned to the web page as MM/DD/YYYY.
I have found that if I choose a date like 02 Feb so I can run the report and
then use the date picker again without exiting, it then returns DD/MM/YYYY.
My client PC is set to UK English and I have checked my IE settings (I have
tried firefox too). The server is all set to UK english. I have checked the
settings on IIS as well.
I have tried forcing the culture to "en-GB" in web.config.
It's interesting to note that the report services log files (eg
ReportServerWebApp__03_16_2007_14_29_30.log) contains en-US.
<Header>
<Product>Microsoft SQL Server Reporting Services Version
9.00.3152.00</Product>
<Locale>en-US</Locale>
<TimeZone>GMT Standard Time</TimeZone>
<Path>C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
Services\LogFiles\ReportServerWebApp__03_16_2007_14_29_30.log</Path>
<SystemName>myservername</SystemName>
<OSName>Microsoft Windows NT 5.2.3790 Service Pack 2</OSName>
<OSVersion>5.2.3790.131072</OSVersion>
</Header>On 16 mar, 16:05, "Paul Cahill" <a...@.anon.com> wrote:
> SQL2005 SP2 + hotfix build 3152
> I'm a newbie to reporting services and I am just learning and testing at the
> moment. I am based in the UK.
> I have set up a report with two parameters that are both dates.
> When running the report in the IDE orhttp://ServerName/Reportsdates picked
> from the calendar control return as DD/MM/YYYY
> When I run the report throughhttp://Servername/ReportServerthe date is
> returned to the web page as MM/DD/YYYY.
> I have found that if I choose a date like 02 Feb so I can run the report and
> then use thedate pickeragain without exiting, it then returns DD/MM/YYYY.
> My client PC is set to UK English and I have checked my IE settings (I have
> tried firefox too). The server is all set to UK english. I have checked the
> settings on IIS as well.
> I have tried forcing the culture to "en-GB" in web.config.
> It's interesting to note that the report services log files (eg
> ReportServerWebApp__03_16_2007_14_29_30.log) contains en-US.
> <Header>
> <Product>MicrosoftSQLServer Reporting Services Version
> 9.00.3152.00</Product>
> <Locale>en-US</Locale>
> <TimeZone>GMT Standard Time</TimeZone>
> <Path>C:\Program Files\MicrosoftSQLServer\MSSQL.3\Reporting
> Services\LogFiles\ReportServerWebApp__03_16_2007_14_29_30.log</Path>
> <SystemName>myservername</SystemName>
> <OSName>Microsoft Windows NT 5.2.3790 Service Pack 2</OSName>
> <OSVersion>5.2.3790.131072</OSVersion>
> </Header>
Exactly the same problem here, it is caused by SP2 and his new date-
picker control. Anyone knows if MS is working to correct this?. Thanks.

Sunday, March 11, 2012

Date formatting - Really newbie question

I have a unbelievably stupid problem that I can't figure out. My table is
imported from access and contains a column with data type datetime. I want
to be able to sum the data (which is a door counter for our store) to show
me all of the traffic for the day, then display the date as 1/1/2007 instead
of 1/1/2007 12:00:00 PM. I have tried this... (which is how I interpret the
BOL help on this topic)...
convert(smalldatetime, [Date], 101)
No matter what I put in the style portion of the select statement it has no
impact on my output format. I suppose I could convert this to a varchar and
trim the results but that seems to be overkill (in addition to beiing a poor
solution).
Solved this. If anyone else is as inexperienced as I am and has this
problem, you can use the following method to change the output of the
datetime in this method.
Select CONVERT(varchar(20), [Date] as DT
will change this
1/30/2007 10:00:00
to this
1/30/2007
"Chuck G." wrote:

> I have a unbelievably stupid problem that I can't figure out. My table is
> imported from access and contains a column with data type datetime. I want
> to be able to sum the data (which is a door counter for our store) to show
> me all of the traffic for the day, then display the date as 1/1/2007 instead
> of 1/1/2007 12:00:00 PM. I have tried this... (which is how I interpret the
> BOL help on this topic)...
> convert(smalldatetime, [Date], 101)
> No matter what I put in the style portion of the select statement it has no
> impact on my output format. I suppose I could convert this to a varchar and
> trim the results but that seems to be overkill (in addition to beiing a poor
> solution).
>
|||I don't quite see how that works (20 is too long, and the is only one
parenthesis). To
convert a datetime value to the same date at midnight, this is one solution:
dateadd(day,datediff(day,0,[Date]),0)
-- Steve Kass
-- Drew University
-- http://www.stevekass.com
Chuck G. wrote:
[vbcol=seagreen]
>Solved this. If anyone else is as inexperienced as I am and has this
>problem, you can use the following method to change the output of the
>datetime in this method.
>Select CONVERT(varchar(20), [Date] as DT
>will change this
>1/30/2007 10:00:00
>to this
>1/30/2007
>"Chuck G." wrote:
>

Friday, February 17, 2012

date calculations using a time hierarchy

Hi There

I am a relative newbie at SSAS 2005, but I've created a working cube and populated it with data.

I have a fact table with three date fields:
[record date]
[start date] - date the product started
[end date] - date the product was withdrawn
+ some other data fields
I use the [record date] to analyse my data with a server-populated time dimension. So far so good, it works fine.
However I need to look at how many days the products were active during the current time period. For exampe, if I'm in Q1 of 2005 and my product ran from 1st december 2004 to 15th january 2005, the answer is 15 days. This needs to be totaled across various other dimensions too.
I have tried a lot of different ways of doing it without much success. Any ideas on how to implement something like this?

ThanksCould you explain the schema, and the granularity of the fact table - for example, is there only 1 record per product, or 1 record per sales transaction? In the latter case, shouldn't the product start and end dates be associated with a Product dimension, rather than with each transaction?|||It's a simplified proof-of-concept project, so I can understand how it works before trying it out on the full database which is more complex.
These are financial products which have a start and end date. There is one record per product and they are to be analysed by various dimensions, for example product type, which would be the maximum granularity (not the products themselves). I also need to look at them by other time dimensions, for example when the records appear in the database, which may be any time after they have actually incepted. So I could have product type on rows and time on columns, and the cells would be the sum of all the days of activity for a given product type for that time period. Or I could have 'appearence time' on rows, so each cell would be the sum of active days for products during the colum time, for all products appearing in a given time frame.
Hope this is clear enough? I realise this is maybe a bit general but I'm only after a general approach strategy rather than an in-depth analysis! Thanks
oh and Merry Christmas!

Tuesday, February 14, 2012

date and time diffs

I'm a newbie to CR so be gentle :) I'm using ver. 10 I'm going againt 2 tables in a SQL database.

The first table has contains problem reports and the second has the remediations they are linked by OutageID. My problem is that on the Problem table there can be several reords that have the same OutageID
but with different status' such as Unavailable, Update, and Available.
There would be only one Unavailable and one Available record but could be none to any number of Update records.
I want to calculate the number of hours and minute of lost time from the Unavailable timestamp to the Available timestamp. How do I code this formula?

ThanksTake a look at DateDiff function in help.