March 8, 2016 at 4:18 pm
Select top 100 CONVERT( CHAR(8), LAB_SCR_DT, 112 ) , * FROM LAB_IN
This will not work..( below )
Create INDEX IDX_334455 on LAB_IN ( CONVERT( CHAR(8), LAB_SCR_DT, 112 ) );
I thought it was possible to create an index that has a expression ? Yes/No ?
Please share your opinion please ?
March 8, 2016 at 5:53 pm
You can add a computed column to the table and then index it.
_____________
Code for TallyGenerator
March 8, 2016 at 6:40 pm
You can also create an indexed view.
-- Itzik Ben-Gan 2001
March 8, 2016 at 7:05 pm
Sergiy (3/8/2016)
You can add a computed column to the table and then index it.
Agreed. I haven't done that since earlier today.
March 9, 2016 at 2:22 am
mw112009 (3/8/2016)
Select top 100 CONVERT( CHAR(8), LAB_SCR_DT, 112 ) , * FROM LAB_INThis will not work..( below )
Create INDEX IDX_334455 on LAB_IN ( CONVERT( CHAR(8), LAB_SCR_DT, 112 ) );
I thought it was possible to create an index that has a expression ? Yes/No ?
Please share your opinion please ?
Is this just a random sample to explain the problem domain or is it quite close to an issue you have with filtering/joining on datetime columns? If it's the latter, then post up a sample or two of affected queries. Datetime arithmetic isn't always intuitive and many folks take a few tries to figure it out. You'll get fixed queries with explanations.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
March 9, 2016 at 5:25 am
Anyone,
I like the idea of a computed column.
Can you share the syntax for that please ?
ALTER TABLE a
ADD dd_date CHAR(8) and then ??????
March 9, 2016 at 5:31 am
Thx to
Sergiy
create table a ( x datetime );
alter table a
add date_char as convert(char(10), x, 112 );
๐
insert into a ( x ) VALUES ( '05/12/2005' );
select * FROM a;
March 9, 2016 at 5:38 am
I'm glad to see you figured it out. Here's some information on your next topic: https://msdn.microsoft.com/en-us/library/ms189292%28v=sql.110%29.aspx
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply