Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Cast efficiency

Author  Topic 

jh_sql
Starting Member

24 Posts

Posted - 2012-05-23 : 04:40:10
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
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-05-23 : 11:52:25
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

24 Posts

Posted - 2012-05-28 : 06:04:59
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

52326 Posts

Posted - 2012-05-28 : 14:09:53
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
   

- Advertisement -