|
What you said is very correct , i am not denying it. The thing is that i am inserting into destination column(smalldatetime) from source column(nvarchar) and the number of records are around 4lac.
I am inserting through sql script in query analyser. After insrting some 20k records it generates that "Arithmetic overflow error".
This was task given to me. thats why otherwise i could change my destination column to datetime. Its working.
But I am forcebly want it to smalldatetime as this was task for me.
|
|
|
|
|
Have you done any data analysis to make sure that all the values you are trying to convert fall into the acceptable range for smalldatetime values?
Perhaps you have a record (around the 20K mark) that has a typo in the date, and instead of 30/11/2009 it's 31/11/2009 (which isn't valid) or 30/11/9999...
|
|
|
|
|
So you have an invalid date in there. Use the isdate function to find any that are invalid.
declare @a nvarchar(20)
set @a = '30/11/2009'
select isdate(@a)
-- returns 1
set @a = '31/11/2009'
select isdate(@a)
-- returns 0
Its not rocket science.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
You were correct there were dates in dd/mm/yyyy which were incorrect format according to ISDATE() function . So i converted it into mm/dd/yyyy format and it worked.
Now thing is that i just saved in date format only like '11/30/2009' but in table having column date (datatype smalldatetime) it stored like '11/30/2009 00:00:00.000'
I want to store only date (datatype=smalldatetime). Is there any way to store into sql server 2005 date column with date only excluding time.
|
|
|
|
|
Lalit singh wrote: Is there any way to store into sql server 2005 date column with date only excluding time.
No, as I said in an earlier post, sql server stores the date and time as a number, not in any format. Just use a format when you display it.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Thank you very much for your valuable response.
|
|
|
|
|
why would you choose smalldatetime when all you want to store is a date?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
Questions such as this explain so much about the world we now find ourselves in
|
|
|
|
|
From the discussion I gather that you are running up against the first problem of storing date data in a non date data format.
You have precicely 1 choice to fix this problem, change your data type to datetime NOW, if you use a work around to convert from nvarchar to datetime then you will always be performing that work around. STOP AND FIX YOUR DATA.
I suggest creating a new column in a datetime format and convert/copy the data to that field. You are already getting an error (arithmetic) so I know your nvarchar data is corrupt. I would recursively convert as much as possible and then manually update the rest.
|
|
|
|
|
let us take the server is down and all the data are corrupted. other than backup,replication, log shipping what can we do to get back the data or make the customer to proceed with the work ?
bala
|
|
|
|
|
How many recovery methods do you want? Restore the database from the last backup. This is the tried and true method of recovering from a complete database failure.
|
|
|
|
|
Type everything back in from scratch?
|
|
|
|
|
I am going through the msdn sql book and am running a very advanced query with a lot of sub-queries. In the book it does not explain the sub-queries in detail. It only shows the query and gives a result set. I am posting the query below so it can be seen. When I run it I am not getting the same results. First, I am not sure of the order of evaluation of each of the sub-queries (i.e. which get run first) and second I don't quite understand the table aliasing being used in the query. If some one could help me understand what is exactally going on, or point me in the right direction that would be great! Query below:
SELECT OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate
FROM Orders AS o1
WHERE OrderDate = (SELECT MAX(OrderDate) AS Expr1
FROM Orders AS o2
WHERE (EmployeeID = o1.EmployeeID) AND
(RequiredDate = (SELECT MAX(RequiredDate) AS Expr1 FROM Orders AS o2
WHERE EmployeeID = o1.EmployeeID) AND (OrderDate = o1.OrderDate)
AND (SELECT MAX(OrderID) AS Expr1 FROM Orders AS o2
WHERE (EmployeeID = o1.EmployeeID) AND ((OrderDate = o1.OrderDate)))))))
I am not saying anything bad about the book but I am just learning advanced querying and someone who is an expert providing a little assistance would be great.
Thanks,
Steve
|
|
|
|
|
|
Is this what you were trying to do?
SELECT o1.OrderID, o1.CustomerID, o1.EmployeeID, o1.OrderDate, o1.RequiredDate
FROM Orders AS o1
WHERE o1.OrderDate = (SELECT MAX(o2.OrderDate)
FROM Orders AS o2
WHERE o2.EmployeeID = o1.EmployeeID)
AND o1.RequiredDate = (SELECT MAX(o3.RequiredDate)
FROM Orders AS o3
WHERE o3.EmployeeID = o1.EmployeeID
AND o3.OrderDate = o1.OrderDate)
AND o1.OrderId = (SELECT MAX(o4.OrderID)
FROM Orders AS o4
WHERE o4.EmployeeID = o1.EmployeeID
AND o4.OrderDate = o1.OrderDate)
I find it much easier to read if I indent the code and explicitly use table alias'. The intent of the sql becomes much clearer.
|
|
|
|
|
Your ordering has made it much more clear. Thanks for that! One last question. Do I read the subqueries from top to bottom or bottom to top. What is the order of execution?
Much thanks,
Steve Holdorf
|
|
|
|
|
There is no "order" invoked by the positioning of the subqueries. SQL will build an execution plan (you REALLY need to study and understand these to get some performance enhancements) that is based on the cost of each query.
I have a base rule that says I use the strongest (returns the least row) filter first but I doubt it makes a difference.
|
|
|
|
|
I use the same approach because it helps clarify my intent but as you say it actually doesn't have any impact upon the query. The Sql Server Query Optimizer will determine the most efficient route based on the latest statistics.
|
|
|
|
|
Below is a multi inner join query that works. The problem is that I don't understand how it is evaluated and need help understanding what it is doing. Can someone explain in detail what the query is doing because I don't quite understand?
SELECT DISTINCT o.OrderDate, c.CompanyName, od.Quantity, p.ProductName
FROM Customers AS c INNER JOIN
Orders AS o ON o.CustomerID = c.CustomerID INNER JOIN
[Order Details] AS od ON od.OrderID = o.OrderID INNER JOIN
Products AS p ON p.ProductID = od.ProductID
Thanks,
Steve Holdorf
|
|
|
|
|
There used to be a good article on CP explaining join types but I couldn't find it, this returns[^] what should help
Basically an inner join returns records that have the same values in the tables on each side of the join.
Orderdetail => product There will be a foriegn key constraint on the OD table that says an orderid cannot be entered unless there is a product record, therefore this join will no do any filtering but will be used as a lookup to get the productname for each orderdetail.
Order => Orderdetail This gets the detail records for each order record and will be a 1 to many join.
Customer => Order is the same as order/detail join
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft is referring to this[^] article.
I are Troll
|
|
|
|
|
Thanks Eddy, that is exactly the article I was after, have to bookmark it for future reference.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You're welcome
|
|
|
|
|
|
There are two databases in different locations.one in my local database server and the other in a remote server. I want to synchronize theses two databases so that the data available in both servers are exactly the same .when ever any dml operation takes place on one server then the other should also be replicated .What are the bottlenecks and the step by step procedure of implementation.
|
|
|
|