|
This is a bad answer, recommending that someone uses varchar for date function is the WORST thing you can do, globalisation (and crappy data) screws them every time. You should only accept a datetime format and use the databases datetime functionality to deal with it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
Thanks for the reply.
First of all, I'm not recommending that someone should use VARCHAR for storing time (date) values. I agree on this part with you.
However, I'm looking at this problem from a different perspective than you do. I'm considering the usage of VARCHARs as given inputs (data type cannot be changed for some reason). Let's take a look at OP's example once more: "eg: 32:10 - 26:10 = 06:00". So 32:10 and 26:10 are VARCHARs and they cannot be converted to DATETIME ...
I made a really bad assumption that OP is aware of DATETIME usage in such situations (as you said) and haven't warned about that.
Regards,
Andrius Leonavicius
modified 29-Jul-14 20:25pm.
|
|
|
|
|
Andrius Leonavicius wrote: I'm considering the usage of VARCHARs as given inputs (which cannot be changed for some reason)
That is a premise I would not accept, if it gets to the database then it must be in a valid format, the OP should be going back to the input and cleaning up the data before it gets into the database. He has more fundamental problems than getting the difference here.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well, you're right. +5 for your answer.
Regards,
Andrius Leonavicius
|
|
|
|
|
Robymon wrote: 32:10 - 26:10
As has been pointed out by others this is NOT a valid data format, either change the format to 2 ints (hours and minutes) or convert them to minutes. You can then work on the data using math or datetime functions.
While Andrius solution is valid for chopping up strings you should not be dealing with strings in the first place. Fix your underlying data problems and this issue disappears.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
<pre lang="SQL">
SELECT [Id],
CONCAT (DATEDIFF(HOUR ,StartDate, EndDate),
N' : ',
(DATEDIFF(MINUTE,StartDate, EndDate) % 60)) as TimeTaken
FROM [dbo].[YourTable]
Above example, I am first finding the Hour, then finding the minutes. Finally, do a Concatenation to get the results in the format of HH:MM. Hopes this helps.
|
|
|
|
|
i completed my education in 2010... i did my course on sql server 2005 dba.. can any tell me were can i find pdf of dba and bi so that i can get a proper grip of it and if possible can anyone share with me a live project that you have performed .. it will be very useful for me to crack the interview .. i wanna attend the interview genuinely..
kindly help me out.... thanks
ganesh...
|
|
|
|
|
If you completed your education 4 years ago on SS 2005, you should probably download an Express version that is a little more current. It may not allow you do everything, but you should be able to do a lot with it.
And to learn, practice. Create a database, implement it. Test it.
Show what you've done before asking for help.
|
|
|
|
|
There are 2 distinct streams when dealing with databases, developer and DBA. CP mostly deals with developer requirements, how to move data around an application and process the data.
If you intend to go down the DBA path, where you maintain the health of the database and development is only incidental to your core role then http://www.sqlservercentral.com/[^] is a good resource. You may also want/need to concentrate on a specific database server.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello everyone,
I have a problem with my SSIS 2012, if I put in made a OLDBE Source with a complex query or composite sample
AS WITH TT
(
SELECT DISTINCT
e.UniqueID e. [Web Id] from Elements e) SELECT
DISTINCT *
'Class' + CAST (ROW_NUMBER () OVER (PARTITION BY [Web Id] ORDER BY [class] DESC) AS NVARCHAR) AS ClassNum
from TT
I have this error:
Exception From HRESULT: 0xC0202009
Error at Get Products SSIS Error Code DTS_E_OLEBDERROR. A OLE DB error has occured. Error code: 0x80004005
An OLE DB record is available. Source "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Syntax Error, permission violation, or nonspecific Reviews another error"
see Exhibit attached
Note that this same package works wonders on my colleague's machine with vs 2010
I do not understand the error!!
modified 24-Jul-14 8:04am.
|
|
|
|
|
This is an English-language forum. Please post your questions in English.
Il s'agit d'un forum de langue anglaise. S'il vous plaît envoyer vos questions en anglais.
https://translate.google.com/[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Is your package running as a SQL Agent job? You might need to change the permissions on the TEMP directory:
http://support.microsoft.com/kb/933835[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i run it from VS2012 so i dont know if it s with sql agent or not (beginner )
and where i can find Temp directory
|
|
|
|
|
If you're running it from Visual Studio, then it's not using SQL Agent, so that's probably not the problem.
There seem to be lots of potential causes for that error message:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
all of this properties are Ok and as i said this same package works wonders on my colleague's machine with vs 2010
i dont think it s a problem with connection string or else
|
|
|
|
|
amioni wrote: e.UniqueID e. [Web Id] from Elements I am not seeing a comma between the two columns you reference, is that correct?
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
it s just an example of a query so dont worry it s with comma in my package, and it s not the problem
|
|
|
|
|
Always read the error message - Syntax Error, permission violation, or nonspecific Reviews another error
There is either:
An error in the sql - you can check this by running the sql in isolation.
A permission issue - harder to track, I would test this by creating a simple SSIS package and try to run it from your code.
Non specific error - eliminate the first two possibilities then look into this.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
NB : when i make this query in Stored procedure and i call it in the oledb source it work fine but not when i make it directly
|
|
|
|
|
I don't understand what that means - I will need more information to be able to help you.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
amioni wrote: NB : when i make this query in Stored procedure and i call it in the oledb source it work fine but not when i make it directly
A user (database) can have different permissions based on direct sql versus stored procs.
|
|
|
|
|
i am working with sa user (dev pc)
|
|
|
|
|
hi,
i answer myself because i found the solution:
with sql server native client 10 we can't add param with subquery
but this problem is resolved with SQL native client 11 (sql server 2012)
thank you
|
|
|
|
|
hi i found a Gregorian date conversion function in sql server but i dont know how i can use it!
could you help me?
|
|
|
|