SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Cast efficiency
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jh_sql
Starting Member

Finland
22 Posts

Posted - 05/23/2012 :  04:40:10  Show Profile  Reply with Quote
Hello

I have problem on casting date + nvarchar field to date. Casting itself works okay with default dateformat:
CAST(CAST(MONTH(PRODUCT.OFFER_DAY) AS nvarchar) + '.' + CAST(DAY(PRODUCT.OFFER_DAY) AS nvarchar) + '.' + CAST(YEAR(PRODUCT.OFFER_DAY) AS nvarchar) + ' ' + ISNULL(PRODUCT.START_TIME, '00:00') AS datetime) AS start_time

Query wich i run runs rather fast, but when i have to run it several times in row (~100), there comes rather big delay, allmost minute before indexes kick in, and ~15 seconds eaven after that.

Is there any more efficient way to do the casting operation?

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 05/23/2012 :  11:52:25  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
please provide DDL and DML and sample real sample data and also datatypes of all these columns you are casting?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

jh_sql
Starting Member

Finland
22 Posts

Posted - 05/28/2012 :  06:04:59  Show Profile  Reply with Quote
Fields are date + nvarchar field for its time. So its Datetimes day, month, year and time part comes from nvarchar field.

But thanks for reply and sorry for late response, i got around this problem by doing the whole result as one, so dont need to loop it anymore. Would be interesting tho to know if this "bottleneck" could be done somehow different.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 05/28/2012 :  14:09:53  Show Profile  Reply with Quote
why do you need to loop? unless there was another reason, there's no need to loop just for date addition.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000