Otana,
Do you happen to know how can we get date value only?
1/1/2005 00:00:00.000
date value:
1/1/2005
Thanks.
Main Topics
Browse All TopicsHi Experts,
How can we convert a variable @presentdate to varchar?
Declare @presentday as datetime
select @PresentDay = convert( datetime, convert( varchar(10), getdate(), 101 ))
select * from table where date1 = @presentday <---------here
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
This just plain sucks. (excuse me)
The SP is very fast, takes 1:30 minutes to finish if I place a manual date
i.e.
dtstart between '1/1/2005' and '1/2/2005'
__________________________
unfortunately when we place
Declare Presentday as datetime
Declare Previousday as datetime
select @PresentDay = convert( datetime, convert( varchar(10), getdate(), 101 ))
select @PreviousDay = dateadd( day, -1, @PresentDay )
__________________________
it's already 3 hours and still running with no results..
Please kindly guide me what could be wrong?
Thanks.
This sometimes happen with local variables.
What type is date1 column of your table ? If it is datetime, try this:
CREATE PROCEDURE sproc_UpdateTemp_Sub
(
@PreviousDay datetime,
@PresentDay datetime
)
AS
select * from table1 where date between @previousday and @presentday
Go
CREATE PROCEDURE sproc_UpdateTemp
AS
DECLARE @PreviousDay datetime
DECLARE @PresentDay datetime
select @PresentDay = convert( datetime, convert( varchar(10), getdate(), 101 ))
select @PreviousDay = dateadd( day, -1, @PresentDay )
exec sproc_UpdateTemp_Sub @PreviousDay, @PresentDay
Go
I know that it seems strange, but very often this approach helps
If date1 is varchar, it will look like this:
CREATE PROCEDURE sproc_UpdateTemp_Sub
(
@PreviousDay varchar(10),
@PresentDay varchar(10)
)
AS
select * from table1 where date between @previousday and @presentday
Go
CREATE PROCEDURE sproc_UpdateTemp
AS
DECLARE @PreviousDay varchar(10)
DECLARE @PresentDay varchar(10)
select @PresentDay = convert( varchar(10), getdate(), 101 )
select @PreviousDay = convert( varchar(10), dateadd( day, -1, getdate() ), 101 )
exec sproc_UpdateTemp_Sub @PreviousDay, @PresentDay
Go
Jan_Franek,
If you could kindly guide me how to extract the information you needed?
>>Does your table have any indices ? Can you check, what index is used when you run your procedure ? And compare it with index used when you run it manually ? <<
what does SQL server says when we place a string like : '3/30/2005' ?
does it take it as a string? varchar? datetime ?
Thanks.
Sorry, I don't use MS SQL, so I don't know, what profiling tools you can use. However - if you can post schema of your table with all indexes, may be we could pick some good one and try to force SQL server to use it.
When you insert '3/30/2005' and use it for datetime column, SQL server will implicitly convert yout varchar into datetime.
The difference between manual execution and procedure is, that manual execution is compiled with exact knowlege of parameters, so compiler can choose best strategy for given parameters, while procedure is compiled at creation time without any information about values, that you will use when invoking it. That's probably why compiler chooses bad index and it results in poor performance.
lynnton
Why are you using varchar instead of datetime datatype? If it is just to lose the time part of GetDate it is much more efficient convert it using a float.
Something like
select cast(floor(convert( float,getdate())) as datetime)
returns you today's date with the time part set to 00:00:00.
You could create a UDT like this:
create function dbo.fnDateFromDateTime(@da
returns datetime
AS
begin
return cast(floor(convert( float,@datetime)) as datetime)
end
And call it like this:
select dbo.fnDateFromDateTime(Get
Business Accounts
Answer for Membership
by: OtanaPosted on 2005-04-01 at 03:22:38ID: 13679874
cast(@presentdate as varchar(20))