Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Tuesday, March 27, 2012

Ho to Convert Varchar datatype into datetime


declare @.a varchar(10)
select @.a= shiftstarttime from o_parameter
print @.a

declare @.b varchar(10)
select @.b= shiftendtime from o_parameter
print @.b


declare @.dt varchar(20)
set @.dt=Left(getdate(),12)

print @.dt

declare @.dt1 varchar(20)
set @.dt1=Left(dateadd(dd, 1,getdate()),12)
print @.dt1

declare @.dt3 varchar(20)

set @.dt3= @.dt1 + space(0) + @.a

print @.dt3

declare @.dt4 varchar(20)

set @.dt4= @.dt + space(0) + @.b

print @.dt4

output of above script is as fallow

09.30am
06.30pm
Aug 22 2007
Aug 23 2007
Aug 23 2007 09.30am
Aug 22 2007 06.30pm

now i want to convert @.dt3 and @.dt4 into datetime .

because i wnat to calculate datedifference in hours by using this function

SET @.in_hour=DATEDIFF (HH ,@.D1,@.D2)

where @.D1 and @.D2 are datetime parameters.

but how can i get @.dt3 and @.dt4 into datetime so i can pass it to DATEDIFF() function.

so plz Guide me. or if u know how to write it then plz write here

i already use cast for it but it doesn't work.

so plz reply urgently.

Try this:

Code Snippet

DECLARE @.dt3 varchar(20), @.dt4 varchar(20), @.in_hour int

SET @.dt3 = 'AUG 23 2007 09:30am'

SET @.dt4 = 'AUG 23 2007 06:30am'

SET @.in_hour=DATEDIFF(HH,CAST(@.dt3 as datetime), CAST(@.dt4 as datetime))

SELECT @.in_hour

or

Code Snippet

DECLARE @.dt3 datetime, @.dt4 datetime, @.in_hour int

SET @.dt3 = CAST('AUG 23 2007 09:30am' as datetime)

SET @.dt4 = CAST('AUG 23 2007 06:30am' as datetime)

SET @.in_hour=DATEDIFF(HH,@.dt3,@.dt4)

SELECT @.in_hour

|||

You can use the following query,

Code Snippet

select

Datediff(HH,

cast(Convert(varchar, dateadd(dd, 1,getdate()),101) + ' ' + replace(shiftstarttime,'.',':') as datetime),

cast(Convert(varchar, dateadd(dd, 1,getdate()),101) + ' ' + replace(shiftendtime,'.',':') as datetime))

from

o_parameter

--or

Select datediff(HH,Convert(datetime, replace(shiftstarttime,'.',':')), Convert(datetime, replace(shiftendtime,'.',':')))

from

o_parameter

Friday, March 23, 2012

high-speed insert

I have been using an OODB as the repository for a stock-quote ticker plant.
I would love to be able to convert this to SQL Server.
Quotes come in at a nominal rate of 10K per second with peaks up to 60K.
The quote is fairly basic data: time, price, volume, ExchangeID - leaving ou
t
the minor variations. I already have this data in a write cache in C#, so
the data could be cached per stock symbol. While this data is flying in, I
also will be querying a bit heavily also.
1) Is this even thinkable with SQL Server 2005 Express, Standard or
Enterprise?
2) I haven't had much luck with good ole Google in finding some direction.
I'm obviously not a SQLServer expert, but given a pointer towards the write
technology and methods, I might have hope.
3) There is a major Stock Trading Technology company that says they use SQL
Server 2005 for this purpose. Of course, they don't describe the methods.
This is at
http://members.microsoft.com/Custom...1&LanguageID=1.
Thanks for any help you might provideLarry wrote:
> I have been using an OODB as the repository for a stock-quote ticker
> plant.
> I would love to be able to convert this to SQL Server.
> Quotes come in at a nominal rate of 10K per second with peaks up to
> 60K.
> The quote is fairly basic data: time, price, volume, ExchangeID -
> leaving out the minor variations. I already have this data in a
> write cache in C#, so the data could be cached per stock symbol.
> While this data is flying in, I also will be querying a bit heavily
> also.
> 1) Is this even thinkable with SQL Server 2005 Express, Standard or
> Enterprise?
> 2) I haven't had much luck with good ole Google in finding some
> direction. I'm obviously not a SQLServer expert, but given a pointer
> towards the write technology and methods, I might have hope.
> 3) There is a major Stock Trading Technology company that says they
> use SQL Server 2005 for this purpose. Of course, they don't describe
> the methods. This is at
> http://members.microsoft.com/Custom...1&LanguageID=1.
> Thanks for any help you might provide
With the right hardware, the right multi-threaded application, and the
right database design, you could do it. I don't know that C# would be my
first choice for that type of application performance. C/C++ will likely
yield better performance. You'll likely need a multi-threaded app,
persistent connections, stored procedures, fast hardware and a properly
designed disk-subsystem. What is the querying for?
This type of project will require careful planning and design. You
should definitely enlist resources who have done this before, since even
the smallest mistake can cause problems.
http://www.microsoft.com/sql/prodin...calability.mspx
David Gugick - SQL Server MVP
Quest Software|||If your requirement is to insert the raw quote data, I suggest you look into
the SqlBulkCopy class, introduced in .NET 2.0. This ought to be able to
insert at a rate of tens-of-thousands of rows per second.
Hope this helps.
Dan Guzman
SQL Server MVP
"Larry" <Larry@.discussions.microsoft.com> wrote in message
news:9F9E926F-74A4-4038-B4F5-CFC55488CD19@.microsoft.com...
>I have been using an OODB as the repository for a stock-quote ticker plant.
> I would love to be able to convert this to SQL Server.
> Quotes come in at a nominal rate of 10K per second with peaks up to 60K.
> The quote is fairly basic data: time, price, volume, ExchangeID - leaving
> out
> the minor variations. I already have this data in a write cache in C#, so
> the data could be cached per stock symbol. While this data is flying in,
> I
> also will be querying a bit heavily also.
> 1) Is this even thinkable with SQL Server 2005 Express, Standard or
> Enterprise?
> 2) I haven't had much luck with good ole Google in finding some direction.
> I'm obviously not a SQLServer expert, but given a pointer towards the
> write
> technology and methods, I might have hope.
> 3) There is a major Stock Trading Technology company that says they use
> SQL
> Server 2005 for this purpose. Of course, they don't describe the methods.
> This is at
> http://members.microsoft.com/Custom...1&LanguageID=1.
> Thanks for any help you might provide