Thursday, March 29, 2012
DB backup failure on 3rd party tool
We are backing up this SQL database server using 3rd party
tool from CommVault. About once every a couple of months
the backups stop working. The backup jobs on CommVault
just hang. We have to reboot the SQL server to fix the
problem. And rebooting has been working well so far. We
had CommVault support worked on the problem and they
didn't find anything in their error log. So we started
looking at the windows 2000 server/SQL server 2000 side
trying to find any clue. I looked at SQL errorlog, system
Event Viewer but didn't see anything. Do you have any
suggestions about where else can I look? And any advice of
how to debug this prolem will be greatly appreciated! LiNothing in SQL logs and Window logs: you better ask the vendor. They must
have a clue.
"Li" <lichenzhao@.yahoo.com> wrote in message
news:00c001c3a305$7fa0bb70$a501280a@.phx.gbl...
> Hi,
> We are backing up this SQL database server using 3rd party
> tool from CommVault. About once every a couple of months
> the backups stop working. The backup jobs on CommVault
> just hang. We have to reboot the SQL server to fix the
> problem. And rebooting has been working well so far. We
> had CommVault support worked on the problem and they
> didn't find anything in their error log. So we started
> looking at the windows 2000 server/SQL server 2000 side
> trying to find any clue. I looked at SQL errorlog, system
> Event Viewer but didn't see anything. Do you have any
> suggestions about where else can I look? And any advice of
> how to debug this prolem will be greatly appreciated! Li
Sunday, March 25, 2012
DAY() not working with 'Left Join'?
I have two tables. Days (1-31) and dates (random dates)
If I have a query that is
Select Day, Date
From days LEFT JOIN dates ON days.Day = DAY(dates.date)
Order By Day, Date
The left join will not return all the days in days just the ones that join with dates. It returns as if I am doing and 'Inner join'. What do I need to do different?
Thanks.
ry this:
Select a.Day, b.date
From days a LEFT JOIN dates b ON a.Day = DAY(b.date)
Order By a.Day, b.date
|||That didn't seem to do anything. What was the thought behind this if you don't mind?|||CREATE TABLE [dbo].[Dates]([Date] [datetime] NULL,
[id] [int] NULL)
INSERT INTO [Dates] ([Date],[id])VALUES('Oct 2 2006 12:00:00:000AM',1)
INSERT INTO [Dates] ([Date],[id])VALUES('Oct 4 2006 12:00:00:000AM',2)
CREATE TABLE [Days]([Day] [int] NULL)
INSERT INTO [Days] ([Day])VALUES(1)
INSERT INTO [Days] ([Day])VALUES(2)
INSERT INTO [Days] ([Day])VALUES(3)
INSERT INTO [Days] ([Day])VALUES(4)
INSERT INTO [Days] ([Day])VALUES(5)
INSERT INTO [Days] ([Day])VALUES(6)
INSERT INTO [Days] ([Day])VALUES(7)
INSERT INTO [Days] ([Day])VALUES(8)
INSERT INTO [Days] ([Day])VALUES(9)
INSERT INTO [Days] ([Day])VALUES(10)
INSERT INTO [Days] ([Day])VALUES(11)
INSERT INTO [Days] ([Day])VALUES(12)
INSERT INTO [Days] ([Day])VALUES(13)
INSERT INTO [Days] ([Day])VALUES(14)
INSERT INTO [Days] ([Day])VALUES(15)
INSERT INTO [Days] ([Day])VALUES(16)
INSERT INTO [Days] ([Day])VALUES(17)
INSERT INTO [Days] ([Day])VALUES(18)
INSERT INTO [Days] ([Day])VALUES(19)
INSERT INTO [Days] ([Day])VALUES(20)
INSERT INTO [Days] ([Day])VALUES(21)
INSERT INTO [Days] ([Day])VALUES(22)
INSERT INTO [Days] ([Day])VALUES(23)
INSERT INTO [Days] ([Day])VALUES(24)
INSERT INTO [Days] ([Day])VALUES(25)
INSERT INTO [Days] ([Day])VALUES(26)
INSERT INTO [Days] ([Day])VALUES(27)
INSERT INTO [Days] ([Day])VALUES(28)
INSERT INTO [Days] ([Day])VALUES(29)
INSERT INTO [Days] ([Day])VALUES(30)
INSERT INTO [Days] ([Day])VALUES(31)
And the script that works:
Select a.Day, b.date
From days a LEFT JOIN dates b ON a.Day = DAY(b.date)
Order By a.Day, b.date
If you cannot run this, let's see what is the problem again.
|||So I get to playing around with your example and descovered some stuff I didn't know about left joins.
My query has touble when I add a Where clause on it to filter dates to a certain range. The differents querys are below in case someone else needs help. Thanks.
NOT WORKING
Select a.Day, b.date
From days a LEFT JOIN dateshiftcrewTable b ON a.Day = DAY(b.date)
Where b.date Between '1/1/1999' and '4/4/1999'
Order By a.Day, b.date
WORKING
Select a.Day, b.date
From days a LEFT JOIN dateshiftcrewTable b ON a.Day = DAY(b.date) and
b.date Between '1/1/1999' and '4/4/1999'
Order By a.Day, b.date
|||If you use a subquery with a where clause fro your LEFT JOIN, it should work.
Select a.Day, b.date
From days a LEFT JOIN (select * FROM dateshiftcrewTable Where date Between '1/1/1999' and '4/4/1999') b ON a.Day = DAY(b.date)
Order By a.Day, b.date
Day of week expression for parameter
entered 2 working days ago. I have used a default date-time parameter
in the past to do something similar for another report. I will be
running the report daily and elivering by subscrition, so the parameter
needs to be part of the report. In this case, I want the expression to
evaluate what day of the week it is today and calculate what the date
was 2 working days ago. For example:
If today is Monday, then get last Thursday's date = today -4 days.
If today is Tuesday, then use the range Friday to Sunday (in case
anything is entered over the weekend) = -4 to -2 days.
If today is Wednesday, then get Monday's date = today -2 days.
If today is Thursday, then get Tuesday's date = today -2 days.
If today is Friday, then get Wednesday's date = today -2 days.
Can anybody help me - I'm struggling with how to use the date functions
like this?
Thanks!agenda9533 had a similar question and the answer was writing a user function
Search using DATEDIFF and look for agenda9533 's posting
Thursday, March 22, 2012
David Portas on Any one? Query Help Please
I got that query working,
SELECT P.productname, COUNT(S.productname)
FROM Products AS P
LEFT JOIN Sales AS S
ON P.productname = S.productname
GROUP BY P.productname ;
but what if there was another column CustomerId, which exists in both tables
and I want to just see products just for a particular customer?
So if a product is offered to a customer , but he doesn't order it then in
result I want to show that product with count as 0...Try this:
SELECT P.productname, COUNT(S.productname)
FROM Products AS P
LEFT JOIN Sales AS S
ON P.productname = S.productname
AND P.customerid = S.customerid
WHERE P.customerid = /* specify the required customer */
GROUP BY P.productname ;
The best way to get help with a problem such as this is to post DDL and
sample data. The following artcile explains how:
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||Thnx David,
It worked for me.
"David Portas" wrote:
> Try this:
> SELECT P.productname, COUNT(S.productname)
> FROM Products AS P
> LEFT JOIN Sales AS S
> ON P.productname = S.productname
> AND P.customerid = S.customerid
> WHERE P.customerid = /* specify the required customer */
> GROUP BY P.productname ;
> The best way to get help with a problem such as this is to post DDL and
> sample data. The following artcile explains how:
> http://www.aspfaq.com/etiquette.asp?id=5006
> --
> David Portas
> SQL Server MVP
> --
>
>sql
Dattime format problems when retrieved on FreeBSD server
I'm using MSSQL with PHP and this works fine on a Windows server.
When i move to a FreeBSD server, the date formatting is not working.
FreeBSD retrieves the date as: mon dd yyyy hh:mi:ss:mmmAM - and php's functions for formatting date fails.
I've tried using: Convert(varchar(10), Date, 103) AS Date, and the date is formatted fine - BUT sorting on date does NOT work.
Are there any way i can do changes to datetime behaviour on server side? I NEVER wants the date in mon dd yyyy hh:mi:ss:mmmAM. I don't need milliseconds, and i want 24h format - not AM/PM. Are there any settings on the SQL server for this?
Where are you doing your sorting? With T-SQL CONVERT-style affects sort:
ORDERBYConvert(nvarchar(30), OrderDate, 109)
|||I'm not sure what you mean. I SELECT Convert(varchar(10), Date, 103) AS Date, and last sentence is ORDER BY Date DESC.
Anyway - i would prefer to fix this server-side if possible, so that i don't need to rewrite all queries adding convert functions etc...
|||If you want to ORDER BY the output of Convert(varchar(10), Date, 103) then you have to put that expression in the ODER BY clause not simply the column named Date.|||I'll try that, but i don't think it will work, because it returns the date as a string, and thus sorting the strings from highest numbers, to lower, which does not not necessarily need to be correct(?)
Is this really the only reason to make it work?
Dattime format problems when retrieved on FreeBSD server
I'm using MSSQL with PHP and this works fine on a Windows server.
When i move to a FreeBSD server, the date formatting is not working.
FreeBSD retrieves the date as: mon dd yyyy hh:mi:ss:mmmAM - and php's functions for formatting date fails.
I've tried using: Convert(varchar(10), Date, 103) AS Date, and the date is formatted fine - BUT sorting on date does NOT work.
Are there any way i can do changes to datetime behaviour on server side? I NEVER wants the date in mon dd yyyy hh:mi:ss:mmmAM. I don't need milliseconds, and i want 24h format - not AM/PM. Are there any settings on the SQL server for this?
Where are you doing your sorting? With T-SQL CONVERT-style affects sort:
ORDERBYConvert(nvarchar(30), OrderDate, 109)
|||I'm not sure what you mean. I SELECT Convert(varchar(10), Date, 103) AS Date, and last sentence is ORDER BY Date DESC.
Anyway - i would prefer to fix this server-side if possible, so that i don't need to rewrite all queries adding convert functions etc...
|||If you want to ORDER BY the output of Convert(varchar(10), Date, 103) then you have to put that expression in the ODER BY clause not simply the column named Date.|||I'll try that, but i don't think it will work, because it returns the date as a string, and thus sorting the strings from highest numbers, to lower, which does not not necessarily need to be correct(?)
Is this really the only reason to make it work?
datetime to integer
Ahh, now we get down to it. When you say date/time is unique in all tables, my knee-jerk reaction is "Really? How are you assuring that" But know I am lead to believe that the source of the data is a data source that supplies more date/time precision than SQL Server records natively.
Key question: To what precision are you maintaining your date/time information?
Key question: How are you assuring that all date/time fields are unique? This is not a common guarantee in SQL Server.
|||The data comes from several "clean" sources. The datetime field is set as a primary key. During import, checks for duplicate datetime values are made. After import, the data is cleaned again.
Most of the data is in one minute intervals.
When you say uniqueness is not a common guarantee, are you saying that setting a field to primary key or unique does not work properly in SQL Server?
|||If your granularity is finer than millisecond granularity then you will need an alternative to native datetime datatype. The native datetime datatype only tracks to 1/300th of a second.|||Most of the data is at one minute or higher (10 minute, hourly, etc.) levels. The possibility exists of sampling data as fine as one second intervals. Nothing will be done at the millisecond level.|||I think I would stick with native datetime; can we get additional opinions please?|||If I recall correctly, internally SQL Server stores datetime values as a decimal number comprised of a (left side) four byte integer representing the number of days since Day 0 (Jan 01, 1900) , separating decimal, and a (right side) four byte integer representing the number of milliseconds since midnight.
So while not stored as an Integer, it is stored in the 'next best thing'.
|||Yes, however, that is NOT to the nearest millisecond but to the nearest 1/300 of a second; it is a legacy from Sybase.sqlWednesday, March 21, 2012
datetime params quit working when i switched from ws to wcf
hi
HHello!, the following 3 webmethods still work after i switched them to WCF but now it never accepts my parameters. i didn't change anything in reporting services, but i have a feeling it's not sending the params to the service anymore.
is there an operation contract attribute change i need to make to require the datetime be provided by RS?
here's the schema provided by my serviec wsdl (the relevant portion)
- <xs:element name="EeoByAssignmentReport">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="start" type="xs:dateTime" />
<xs:element minOccurs="0" name="end" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="EeoByAssignmentReportResponse">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="EeoByAssignmentReportResult" nillable="true">
- <xs:complexType>
- <xs:annotation>
- <xs:appinfo>
<ActualType Name="DataSet" Namespace="http://schemas.datacontract.org/2004/07/System.Data" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" />
</xs:appinfo>
</xs:annotation>
- <xs:sequence>
<xs:element ref="xs:schema" />
<xs:any />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="EeoByPersonReport">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="start" type="xs:dateTime" />
<xs:element minOccurs="0" name="end" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="EeoByPersonReportResponse">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="EeoByPersonReportResult" nillable="true">
- <xs:complexType>
- <xs:annotation>
- <xs:appinfo>
<ActualType Name="DataSet" Namespace="http://schemas.datacontract.org/2004/07/System.Data" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" />
</xs:appinfo>
</xs:annotation>
- <xs:sequence>
<xs:element ref="xs:schema" />
<xs:any />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="EeoCountsReport">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="start" type="xs:dateTime" />
<xs:element minOccurs="0" name="end" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="EeoCountsReportResponse">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="EeoCountsReportResult" nillable="true">
- <xs:complexType>
- <xs:annotation>
- <xs:appinfo>
<ActualType Name="DataSet" Namespace="http://schemas.datacontract.org/2004/07/System.Data" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" />
</xs:appinfo>
</xs:annotation>
- <xs:sequence>
<xs:element ref="xs:schema" />
<xs:any />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
the reason i suspect it's not sending the data is because i have another method that takes a uint, and somehow the client proxy automatically generated a new bool property called <myuintname>Provided (or something like that) and now i always have to set that to true or it won't send the uint... I think that's what is happening here, except i have no way to set such a property since i'm sending pure primitaves no message contracts or anything.
i have to admit this behavior in the wcf is extremely frustrating, because all it does is zero out the field when you don't provide t he bool flag...which if i didn't want to send anything it would automatically be zero'd out because i didn't set it to anything.... makes no sense at all.
Monday, March 19, 2012
Datetime only time needed
I'm working with an excisting database using MSSQL, where are 2 T_datetime
fields.
If i display these 2 columns i see the date time format as follow:
Aug 5 2004 6:03PM
The problem is that i only need de time format like 6:03PM or better if
possible 18:03.
Could anybody help mee with these 2 problems.See function CONVERT in BOL. It is better to do the formatting in your clien
t
app, reporting tool, or programming language.
select left(right(convert(varchar(25), getdate(), 100), 7), 5)
AMB
"Smarteye" wrote:
> Wel maybe someone could help me.
> I'm working with an excisting database using MSSQL, where are 2 T_datetime
> fields.
> If i display these 2 columns i see the date time format as follow:
> Aug 5 2004 6:03PM
> The problem is that i only need de time format like 6:03PM or better if
> possible 18:03.
> Could anybody help mee with these 2 problems.|||I cannot change the excisting Database,
If i use this code i see no output in Php.
does any know
"Alejandro Mesa" wrote:
> See function CONVERT in BOL. It is better to do the formatting in your cli
ent
> app, reporting tool, or programming language.
>
> select left(right(convert(varchar(25), getdate(), 100), 7), 5)
>
> AMB
>
> "Smarteye" wrote:
>|||> I cannot change the excisting Database,
I did not say to change the db.
> If i use this code i see no output in Php.
> does any know
>
Which code?
AMB
"Smarteye" wrote:
> I cannot change the excisting Database,
> If i use this code i see no output in Php.
> does any know
> "Alejandro Mesa" wrote:
>|||What do you mean, if I display these 2 columns? Can you do a select in QA
and post the results?
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Smarteye" <Smarteye@.discussions.microsoft.com> wrote in message
news:4EDDC42C-6CCE-4685-B84E-936C177C2E6A@.microsoft.com...
> Wel maybe someone could help me.
> I'm working with an excisting database using MSSQL, where are 2 T_datetime
> fields.
> If i display these 2 columns i see the date time format as follow:
> Aug 5 2004 6:03PM
> The problem is that i only need de time format like 6:03PM or better if
> possible 18:03.
> Could anybody help mee with these 2 problems.|||$query = " select left(right(convert(varchar(25), PunchIn(), 100), 7), 5)";
//punch in is columname
this is my query what was suggest when i use this i have no output.
"Louis Davidson" wrote:
> What do you mean, if I display these 2 columns? Can you do a select in QA
> and post the results?
> --
> ----
--
> Louis Davidson - drsql@.hotmail.com
> SQL Server MVP
> Compass Technology Management - www.compass.net
> Pro SQL Server 2000 Database Design -
> http://www.apress.com/book/bookDisplay.html?bID=266
> Blog - http://spaces.msn.com/members/drsql/
> Note: Please reply to the newsgroups only unless you are interested in
> consulting services. All other replies may be ignored :)
> "Smarteye" <Smarteye@.discussions.microsoft.com> wrote in message
> news:4EDDC42C-6CCE-4685-B84E-936C177C2E6A@.microsoft.com...
>
>|||What is punchIn() or punchLn(). This is not valid SQL. Can you print what
is in your $query variable and post?
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"Smarteye" <Smarteye@.discussions.microsoft.com> wrote in message
news:40399FA1-87F5-4D8A-97B9-F1F655F814B7@.microsoft.com...
> $query = " select left(right(convert(varchar(25), PunchIn(), 100), 7),
> 5)";
> //punch in is columname
> this is my query what was suggest when i use this i have no output.
> "Louis Davidson" wrote:
>|||Well it's working,
for one field if i do :
$query = " SELECT left(right(convert(varchar(25), PunchIn,100), 7), 7) FROM
X_PunchIn"; //punch in is columname
it wil display the time good.
but i need to display 2 columns
so i've made a 2nd query :
$query2 = "SELECT left(right(convert(varchar(25), PunchOut,100), 7), 5) FROM
X_PunchIn"; //punch in is columname
but mssql could only display 1 query so i've a problem .
Could any one solve this problem? and the problem AM/PM to 24hours
"Louis Davidson" wrote:
> What is punchIn() or punchLn(). This is not valid SQL. Can you print wha
t
> is in your $query variable and post?
> --
> ----
--
> Louis Davidson - drsql@.hotmail.com
> SQL Server MVP
> Compass Technology Management - www.compass.net
> Pro SQL Server 2000 Database Design -
> http://www.apress.com/book/bookDisplay.html?bID=266
> Blog - http://spaces.msn.com/members/drsql/
> Note: Please reply to the newsgroups only unless you are interested in
> consulting services. All other replies may be ignored :)
> "Smarteye" <Smarteye@.discussions.microsoft.com> wrote in message
> news:40399FA1-87F5-4D8A-97B9-F1F655F814B7@.microsoft.com...
>
>
Thursday, March 8, 2012
DateTime conversion from GST to EST
We had a formula that was working until this year when the dates on DST changed. (Probably redundant but changed from the 1st Sunday/April thru last Sunday/Oct to 2nd Sunday/March thru 1st Sunday/Nov).
This is what we were doing before; ugly but it worked...
Date
date({PROBSUMMARY1.OPEN_TIME})
DayLite
if Month({PROBSUMMARY1.OPEN_TIME}) in 4 to 10 then else 5
Time
time({PROBSUMMARY1>OPEN_TIME})-(({@.DayLite})*3600)
DateAdjATL
if Time({PROBSUMMARY1.OPEN_TIME})<=TimeValue(05,00,00)then
DateTimeValue({@.Date}-1,{@.Time}) else DateTimeValue ({@.Date},{@.Time})
We are currently hard coding the dates and we all know how inefficient that is... ANY HELP IS GREATLY APPRECIATED!!!Looks like something is missing...
DayLite
if Month({PROBSUMMARY1.OPEN_TIME}) in 4 to 10 then else 5
if that is correct, you may need to change the months to
if Month({PROBSUMMARY1.OPEN_TIME}) in 3 to 11 then else 5
Hard to tell....
since you have an if, but no value if the if is true.
if Month({PROBSUMMARY1.OPEN_TIME}) in 4 to 10 then else 5
for example, if Month({prob...}) in 4 to 10 then (What ?) else 5
DateTime confusion.
Hi All,
I'm stumped. I've got a stored procedure with a number of input parameters, and working fine.
I added two extra input parameters, FromDate datetime, ToDate datetime. I have not even included these in the SQL yet and just tried to execute the stored proc alone with manually inputting paramters, but I keep getting error: @.FromDate: this input parameter cannot be converted.
That surely means a formatting issue, so I copy and pasted a value directly from the database into this parameter field, and still get the same error. I've tried various formats, with single and double quotes, and without. But just dont know?
And even when I populate these parameters in my code and call the stored proc, it returns no results either, even though I haven't included these new date paramters in the SQL select, so that means it was in error and no doubt a formatting issue on those date fields.
format I used was: 17/07/2007 00:00:00
I tried to populate the parameters via the code as follows:
Dim dt As DateTime
DateFromTB1.Text = DateTime.Now
DateTime.TryParse(DateFromTB1.Text, dt)
SqlDataSource1.SelectParameters("FromDate").DefaultValue = dt
I know there is an extra step for now (DateFromTB1.Text = DateTime.Now), this step will fall away and just parse the textbox.text field as entered by the user.
Any help appreciated, thanks.
Try this:
string strDate = Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy");
if you want to pass it as string or
DateTime dtDate = Convert.ToDateTime(txtDate.Text).ToUniversalTime();
or
DateTimeFormatInfo myDTFI =newCultureInfo("en-GB",false).DateTimeFormat;
DateTime Dtime =Convert.ToDateTime("31/12/2007", myDTFI);
or
DateTime dtDate = Convert.ToDateTime(txtDate.Text).ToShortDateStrin(); if you are using smalldatatime in your databse.
Also there is a .ToLocalTime() function if that might be any help to you too.
Hope this would help.
|||Hi Mehdi,
thanks for the quick response, I've since discovered that even though the SQL Server Express date format, as displayed in my Show Table Data windows, is dd/mm/yyyy, it is actually expecting mm/dd/yyyy format via my stored proc.
My computer regional settings are dd/mm/yyy, but somehow SQL server settings, or perhaps it's my VWD Express settings are the American version, and I cannot find where to change it. any ideas? thanks.
|||
You can either use SET DATEFORMAT or be more efficient and send the data in YYYYMMDD format irrespective of client's location and not have to worry about converting mdy to dmy to viceversa.
|||thanks for the help, that did the trick.
Saturday, February 25, 2012
Dates not working in SQL query
but works correctly on another - what could make this happen on SQL 2000
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
SELECT count(*)
FROM Contact INNER JOIN
OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
(PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
1, 1980') AND
(PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
(LEFT(OrderHeader.OrderCode, 1) = '1')
AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
NULL)
Regards Jeff
This is the query that gives the error message for 'Oct 9, 2003' on a server
but works correctly on another - what could make this happen on SQL 2000
Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string.
SELECT count(*)
FROM Contact INNER JOIN
OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
(PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
1, 1980') AND
(PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
(LEFT(OrderHeader.OrderCode, 1) = '1')
AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
NULL)
Regards Jeff
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 6/10/2003Jeff
Please refer to BOL for CONVERT function.
"Jeff Williams" <jeff.williams@.hardsoft.com.au> wrote in message
news:#AtCV9SjDHA.1672@.TK2MSFTNGP09.phx.gbl...
> This is the query that gives the error message for 'Oct 9, 2003' on a
server
> but works correctly on another - what could make this happen on SQL 2000
> Server: Msg 241, Level 16, State 1, Line 1
> Syntax error converting datetime from character string.
>
> SELECT count(*)
> FROM Contact INNER JOIN
> OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
> PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
> WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
> (PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
> 1, 1980') AND
> (PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
> (LEFT(OrderHeader.OrderCode, 1) = '1')
> AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
> OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
> NULL)
> Regards Jeff
>
> This is the query that gives the error message for 'Oct 9, 2003' on a
server
> but works correctly on another - what could make this happen on SQL 2000
> Server: Msg 241, Level 16, State 1, Line 1
> Syntax error converting datetime from character string.
>
> SELECT count(*)
> FROM Contact INNER JOIN
> OrderHeader ON Contact.ContactID = OrderHeader.ContactID INNER JOIN
> PledgeDetails ON OrderHeader.OrderID = PledgeDetails.OrderID
> WHERE (PledgeDetails.LastPaymentDate >= 'Oct 9, 2003') AND
> (PledgeDetails.AutoDeduction = 1) AND (PledgeDetails.NextDueDate >= 'Jan
> 1, 1980') AND
> (PledgeDetails.NextDueDate <= 'Oct 9, 2003') AND
> (LEFT(OrderHeader.OrderCode, 1) = '1')
> AND (Contact.flag9 = 0 OR Contact.flag9 IS NULL) AND (Contact.flag10 = 0
> OR Contact.flag10 IS NULL) AND (Contact.flag15 = 0 OR Contact.flag15 IS
> NULL)
> Regards Jeff
>
>
> --
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.524 / Virus Database: 321 - Release Date: 6/10/2003
>
Dates and defaults
We have been working with SQL 2000 for about a year now pretty successfully
except with dates. This just doesn't seem to be correct, we came for the
VFP data world and it worked with dates easier however dates/times only
recently became one so that was always a fun calculation. In the SQL data
table design tools we can set default values for varchar's, bit and float
fields just to name a few but we cannot set a default value for dates so
they are not posted with a null or with a silly date of 1899 or 1900.
We simply want to be able to store a blank value in a date field - for
example, we have a payment received field with the date/time. A customer
has not been paid yet so the date/time field should be blank or empty yet it
forces us to have an erroneous date. When we import data we need to stuff
fields with that bogus date of 1900. I'm sure we have just missed something
so please point us in the correct direction.
Thank you!
ChrisYou can't have an empty datetime like you did in VFP. You need to allow
NULL's and store a NULL instead.
Andrew J. Kelly SQL MVP
"Chris Marsh" <cmarsh@.synergy-intl.com> wrote in message
news:eq308JSJFHA.1948@.TK2MSFTNGP14.phx.gbl...
> Hi,
> We have been working with SQL 2000 for about a year now pretty
> successfully except with dates. This just doesn't seem to be correct, we
> came for the VFP data world and it worked with dates easier however
> dates/times only recently became one so that was always a fun calculation.
> In the SQL data table design tools we can set default values for
> varchar's, bit and float fields just to name a few but we cannot set a
> default value for dates so they are not posted with a null or with a silly
> date of 1899 or 1900.
> We simply want to be able to store a blank value in a date field - for
> example, we have a payment received field with the date/time. A customer
> has not been paid yet so the date/time field should be blank or empty yet
> it forces us to have an erroneous date. When we import data we need to
> stuff fields with that bogus date of 1900. I'm sure we have just missed
> something so please point us in the correct direction.
> Thank you!
> Chris
>|||Either set a default date (a fixed value or based on the the
CURRENT_TIMESTAMP) or allow the value to default to NULL. I don't understand
why you say you can't set a default for the date. What is the problem? Do yo
u
get an error message?
Unlike VFP, SQL Server doesn't have a blank date other than NULL. That
shouldn't really be a problem. Is there some functionality you want that you
can't get from a NULL or another default date value?
David Portas
SQL Server MVP
--
Friday, February 24, 2012
Dates
I have a problem with the DateAdd function
lets say the project is going to end in 35 days
the project is working day is 6 days a week
the report need to give a date in 35 days from now
using 6 days of working days or 5 or 7 working days ?
well 7 days is easy but 5 or 6 or 4 or 3 i have problem with
It sounds like you are trying to add 35 work days to todays date. You can't use the DateAdd function alone. You will need custom code to determine the actual number of days to add. Does your non-work day change (ex. Sunday one week, Sat. the next)? Is it always 6 days or is it based on a special calendar using holidays?|||the work days can change and holiday will be nice to have but it's not require.i have problem with the custom code to change the workdays around to find out when the project will finish|||How are you tracking how many work days there are in a particular week? Are you storing the information anywhere?|||the information is enter in the website.
I have a field in the column of the table
the project manger will enter how many days per week they will be working for the week
or rest of the project life. the days per week doesn't change too much
but it does happen.
dates
I am working on a database table that was imported from an excel spreadsheet
where the date column value is stored as follow(s)
yyyymmdd this seems to be stored as a numeric value and not as a date value.
So I am trying to write a query on this table where I want to break the data
down by months or by w
with this field because of the way the value is stored as a number and not
necessary as a date field. I was wondering if any one had any ideas on how
to query this field.
J. D.Try the expression: CAST( CAST( dt AS VARCHAR ) AS DATETIME )
Anith|||If all the values in this column are 8-digit integers that would be valid
dates in yyyymmdd format, you should be able to refer to
CAST(CAST(yourColumn as char(8)) as datetime)
and then use any date functions you need.
Steve Kass
Drew University
JD wrote:
>Hello Everyone,
>I am working on a database table that was imported from an excel spreadshee
t
>where the date column value is stored as follow(s)
>yyyymmdd this seems to be stored as a numeric value and not as a date value
.
>So I am trying to write a query on this table where I want to break the dat
a
>down by months or by w
>with this field because of the way the value is stored as a number and not
>necessary as a date field. I was wondering if any one had any ideas on how
>to query this field.
>
>
Datepicker date invalid for type
I'm working on a report within the development environment. A couple of the
parameters are Date/Time parameters for which RS provides a Date Picker.
The Date Picker returns dates consistent with my regional settings i.e. in
dd/mm/yyyy format, however, once I've selected a date from the date picker
with a day greater than 12, the message "An error occurred during local
report processing. The value provided for the report parameter "From_Date"
is not valid for its type." Which one would assume is because somewhere
within .NET or RS its expecting dates in mm/dd/yyyy format.
I can certainly type in a date in either mm/dd/yyyy, mmm/dd/yyyy,
dd/mmm/yyyy or even yyyy/mm/dd or yyyy/mmm/dd but once I move out of the date
parameter, RS reformats the date in dd/mm/yyyy format.
Of course we can surive without a date picker, but its a nice feature and a
shame not to use it. I will persevere without it for now and hope that
someone has a resolution to this problem.
How do I get the datepicker and .NET/RS to agree on which format the dates
are in?
thanks
MattI have RS2005. I found installing SP1 fixed the problems I was having
with this.
The correct behaviour is for the datepicker to display the date in the
format according to the browser regional settings.
Prior to SP1 I had to make my date parameters Strings or pick them from
a database list.
BlackDuck wrote:
> Hi,
> I'm working on a report within the development environment. A couple of the
> parameters are Date/Time parameters for which RS provides a Date Picker.
> The Date Picker returns dates consistent with my regional settings i.e. in
> dd/mm/yyyy format, however, once I've selected a date from the date picker
> with a day greater than 12, the message "An error occurred during local
> report processing. The value provided for the report parameter "From_Date"
> is not valid for its type." Which one would assume is because somewhere
> within .NET or RS its expecting dates in mm/dd/yyyy format.
> I can certainly type in a date in either mm/dd/yyyy, mmm/dd/yyyy,
> dd/mmm/yyyy or even yyyy/mm/dd or yyyy/mmm/dd but once I move out of the date
> parameter, RS reformats the date in dd/mm/yyyy format.
> Of course we can surive without a date picker, but its a nice feature and a
> shame not to use it. I will persevere without it for now and hope that
> someone has a resolution to this problem.
> How do I get the datepicker and .NET/RS to agree on which format the dates
> are in?
> thanks
> Matt
datepart function not working
="Includes Date:" & DatePart(""d"", Now() )
BC30518 Overload resolution failed because no accessible 'DatePart' can be
called with these argumentsdatepart is an SQL Server function, not a Reporting services function.
try this:
now().ToString("d")
write your RS function as VB.Net functions.
"Cindy Lee" <cindylee@.hotmail.com> a écrit dans le message de
news:O4KxH7%23gEHA.3988@.tk2msftngp13.phx.gbl...
> when i put this in a text box, i get this error message:
> ="Includes Date:" & DatePart(""d"", Now() )
>
> BC30518 Overload resolution failed because no accessible 'DatePart' can be
> called with these arguments
>
>|||SQL Server Reporting Services 2000 supports a large number of VB .NET
functions including the date manipulation ones.
Included in this set a DatePart() function. Pleaser refer to MSDN for more
information.
--
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jéjé" <willgart@.BBBhotmailAAA.com> wrote in message
news:ub$Jif$gEHA.1972@.TK2MSFTNGP09.phx.gbl...
> datepart is an SQL Server function, not a Reporting services function.
> try this:
> now().ToString("d")
> write your RS function as VB.Net functions.
> "Cindy Lee" <cindylee@.hotmail.com> a écrit dans le message de
> news:O4KxH7%23gEHA.3988@.tk2msftngp13.phx.gbl...
> > when i put this in a text box, i get this error message:
> >
> > ="Includes Date:" & DatePart(""d"", Now() )
> >
> >
> >
> > BC30518 Overload resolution failed because no accessible 'DatePart' can
be
> > called with these arguments
> >
> >
> >
>
Sunday, February 19, 2012
DateDiff: Calculating working days
Yes, this is possible; however, normally you must account for holidays and when all is said and done I would suggest that you give a look to this article:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html
This discusses establishing a calendar table which ought to help with computing "working days".
( Adolf: what does "NB" stand for? )
|||NB this article doesn't discuss different sets of holidayse.g. england, wales, scotland, ireland
have different public holidays despite being in the UK
you may wish to add extra columns to cater for this|||thank you.. I've decided to pinch the calendar table off another db and will try to follow the examples.
DateDiff: Calculating working days
I am trying to use the DateDiff function to calculate the difference between two dates in working days only... Is this possible in SSRS 2005, or can anyone suggest an alternate solution?
Yes, this is possible; however, normally you must account for holidays and when all is said and done I would suggest that you give a look to this article:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html
This discusses establishing a calendar table which ought to help with computing "working days".
( Adolf: what does "NB" stand for? )
|||NB this article doesn't discuss different sets of holidayse.g. england, wales, scotland, ireland
have different public holidays despite being in the UK
you may wish to add extra columns to cater for this|||thank you.. I've decided to pinch the calendar table off another db and will try to follow the examples.
DateDiff That Only Counts Working Days
On a (very slightly) more serious note, what constitutes a "working day" by your definition?
-PatP|||LOL, I definitely realize what days DBAs work... :)
Working days are just the typical Monday through Friday.|||Vacations? Holidays? Snow days? Office closed due to threat of terrorist attack? Those all affect "working days". Or did you mean to ask "I'm trying to create a query to calculate the number of weekdays between two dates, excluding weekends."?|||Would you include Holidays as work days?
IF not I would suggest you have a table calendar with field workday
values 1 , 0
sum the workday field to get your answer.|||Yes, this is what I'm trying to say:
"I'm trying to create a query to calculate the number of weekdays between
two dates, excluding weekends."|||http://www.aspfaq.com/show.asp?id=2453